Python module
Lesson 1
Why Python for data and AI
Where Python shows up in data work, and which skills this module will teach.
beginner20 minRun on your machine
What you will be able to do
- Explain why DE and AI teams standardize on Python scripts
- Name the weekly Python skills this module will teach
- See where Python sits on the DCubes roadmap
Why this matters for data work
Warehouses, APIs, feature jobs, and model training hooks are full of Python. Not because it is the fastest language, but because the ecosystem is deep: files, HTTP, DataFrames, database drivers, and notebooks that share the same syntax.
You already have Linux and Docker. Python is the language that sits on that machine and talks to files and Postgres.
Where Python shows up
- Batch jobs — a script on a schedule: read object storage or a CSV, transform, write a table.
- Glue code — call an API, normalize JSON, land rows in a database.
- Exploration — a notebook to poke at a sample; the production path is still a script.
- AI adjacency — tokenization, evaluation harnesses, and thin clients around model APIs are usually Python. Full ML stacks come later; the basics are the same: venv, functions, files, env vars.
Scripts vs notebooks vs containers
| Form | Role |
|---|---|
Script (.py) |
Source of truth for a job. Runnable as python path/to/job.py. |
Notebook (.ipynb) |
Interactive file for exploration. It is JSON on disk — version carefully. |
| Container | How you ship the script with pinned deps (Docker module). |
This module trains scripts first. One lesson covers notebooks as files so you are not surprised by Jupyter.
Skills you will use weekly
| Skill | What it is for |
|---|---|
| venv + pip | Isolated deps per project; reproducible requirements.txt |
| Types and functions | Clear helpers instead of one giant file |
| pathlib, CSV, JSON | Files as data |
| logging and errors | Jobs that fail loudly and leave a trail |
| httpx | Simple HTTP extracts |
| NumPy / pandas | Arrays and tables in memory |
| psycopg | Insert and query Postgres from Python |
| Modules and typing | Importable code and readable signatures |
What we will not do yet
- We will not teach full SQL (next module) or Git workflows (module after that).
- We will not install Spark, Airflow, or a full ML framework.
- We will not run your Python on the DCubes host.
- We will not use ORMs or migration frameworks — raw psycopg and clear SQL strings only.
Map of this module
- Getting Started — you already did this (
python3+~/dcubes/python-lab). - REPL and scripts.
- Virtualenvs and pip.
- Types and collections.
- Control flow and functions.
- Errors and logging.
- Paths and text files.
- CSV and JSON.
- HTTP and simple APIs.
- NumPy basics. 11–12. pandas: frames, then group/join/write. 13–14. Postgres from Python, then DataFrames ↔ Postgres.
- Scripts, packages, typing.
- Notebooks as files.
- Demo: First Python data shift — generate random retail orders and load Postgres.
Practice on your machine
Confirm the lab still exists:
cd ~/dcubes/python-lab
python3 --version
ls
You should still have hello.py from Getting Started (or recreate it). That is enough for this page.
Common mistakes
- Learning only in a notebook UI. Production will ask for a script and a venv.
- Global
pip installfor every project. The next lesson fixes that with venv. - Skipping Docker. Postgres in later lessons runs in Compose — keep Docker available.