Originally published at Shipped Code.
If you already write Java, Kotlin or JavaScript and someone hands you a Python backend, you will pick up the syntax quickly. Knowing which tools and tutorials are still current takes longer. This roadmap is the order I would learn things in, with what to skip.
TL;DR. Set up every project with
uvand apyproject.toml, so each one gets its own virtual environment and a lockfile. Learn type hints, dataclasses and the standard library. Then build one API with FastAPI (Flask is fine for small services) on PostgreSQL with SQLAlchemy 2 and Alembic, test it with pytest and ship it in Docker. Automation scripts and Odoo modules branch off the same base. Django internals, asyncio internals and data science can wait unless your job needs them.
The path has 6 stages and 2 branches:
-
Project setup:
uv,pyproject.toml, a lockfile. -
Language essentials: type hints, dataclasses, context managers,
pathlib,logging, exceptions. - One web framework: FastAPI for new APIs, Flask for small ones.
- Database: PostgreSQL with SQLAlchemy 2 and Alembic migrations.
- Tests: pytest fixtures and parametrize.
- Ship it: a Docker image configured by environment variables.
- Branch A, automation: command-line scripts that move files, call APIs and run on a schedule.
- Branch B, Odoo: business modules on Odoo's ORM and XML views.
You should be able to write a Python function and a loop. If not, the official tutorial covers that in an afternoon or two. Notes marked "(for Java/Kotlin developers)" are optional. Data science (NumPy, pandas, notebooks) is a different path and is not covered here.
Python is one of the stacks I build client backends with. Mockly, for example, has a Flask and MySQL backend behind its Flutter app.
Which Python version to use
Start new projects on Python 3.14 or 3.15. The devguide's version table lists both as bugfix releases, with 3.15 out since 9 October 2026, while 3.13 now receives security fixes only. If a library you depend on has no wheels for 3.15 yet, 3.14 is the safe pick. The examples in this post run on CPython 3.14.7 with uv 0.12, FastAPI 0.165, SQLAlchemy 2.1 and pytest 9.2.
Stage 1: Project setup with uv and pyproject.toml
Every project gets its own isolated environment and a file that pins what it depends on. uv does both. It creates the virtual environment (.venv), installs the Python version you ask for, resolves dependencies and writes a uv.lock file you commit. The older route, python -m venv plus pip install -r requirements.txt, still works, but you manage the environment, the pins and the Python version by hand.
This pyproject.toml covers the API and tests in stages 3 and 5 (Stage 4 adds the database packages):
[project]
name = "orders-api"
version = "0.1.0"
requires-python = ">=3.14"
dependencies = ["fastapi>=0.165"]
[dependency-groups]
dev = ["pytest>=9.2", "httpx2>=2.16"]
uv sync
Using CPython 3.14.7
Creating virtual environment at: .venv
Resolved 22 packages in 2ms
Installed 20 packages in 11ms
From then on, uv run pytest or uv run python script.py runs inside that environment, and nobody has to remember to activate it. uv add sqlalchemy updates both files for you. The packaging guide documents every field, and Python project setup with uv covers this stage step by step, including how it compares with venv and pip.
uv init can generate this file too. With uv 0.12 it also adds a src/ layout, a build backend and your git name and email in authors. That is useful for a library you publish. For an API you only deploy, the 8 lines above are enough.
Warning: do not
pip installinto the system Python. Recent Debian and Ubuntu releases, and Homebrew's Python, mark it as externally managed (PEP 668), so pip refuses. On Debian 12 the message starts like this:error: externally-managed-environment × This environment is externally managed ╰─> To install Python packages system-wide, try apt install python3-xyz, where xyz is the package you are trying to install.The fix is a virtual environment, which
uv synccreates for you. Passing--break-system-packagesmakes the error go away, along with the protection the OS relies on.
Stage 2: The language essentials for backend work
Backend Python leans on a small part of the language, so spend your time there:
- Type hints on every function signature. Python ignores them at runtime, but FastAPI, Pydantic, SQLAlchemy 2 and your editor all read them.
- Dataclasses for plain data holders.
-
Context managers (
with) for anything you must close: files, database sessions, locks. -
pathlibinstead of string paths, andlogginginstead ofprint. -
Exceptions: raise specific ones, catch them at the edge (the HTTP handler, the script's
main), and let the rest propagate.
(for Java/Kotlin developers) 3 differences that bite
This file shows 2 of them. It runs as-is with uv run python gotchas.py.
from dataclasses import dataclass, field
from typing import Protocol
def add_tag(tag: str, tags: list[str] = []) -> list[str]:
tags.append(tag)
return tags
print(add_tag("a"))
print(add_tag("b")) # expected ['b']
@dataclass
class Order:
id: int
tags: list[str] = field(default_factory=list)
class Notifier(Protocol):
def send(self, text: str) -> None: ...
class ConsoleNotifier: # never mentions Notifier
def send(self, text: str) -> None:
print("sent:", text)
def confirm(order: Order, notifier: Notifier) -> None:
notifier.send(f"order {order.id} confirmed")
confirm(Order(id=7), ConsoleNotifier())
print(Order(1), Order(2).tags is Order(3).tags)
['a']
['a', 'b']
sent: order 7 confirmed
Order(id=1, tags=[]) False
First, a default argument is evaluated once, when the function is defined, so every call that skips tags shares the same list. The second call returns ['a', 'b']. Use None as the default and create the list inside, or field(default_factory=list) in a dataclass, which is why each Order gets its own list (False on the last line).
Second, there are no interfaces to implement. ConsoleNotifier never mentions Notifier, yet a type checker such as mypy or Pyright accepts it, because a Protocol matches any class with the right methods. At runtime Python checks nothing, it simply calls send.
Third, the standard CPython build still has a global interpreter lock (GIL), so threads do not run Python code in parallel. A separate free-threaded build exists. For a typical I/O-bound API this rarely matters, but it explains why CPU-heavy work goes to processes, not threads.
Stage 3: Pick one web framework
The 3 common choices differ mostly in how much they decide for you. Build one real API with your pick before you look at the others.
| Framework | When to use | Main trade-off |
|---|---|---|
| FastAPI | New JSON APIs, especially for mobile or web clients | Validation and OpenAPI docs come from type hints, but you choose and wire the database, auth and project layout yourself |
| Flask | Small services, webhooks, existing Flask code | Minimal and well understood; validation and API docs need extensions |
| Django | Apps that want an admin panel, auth and an ORM out of the box | Many batteries, but you work within its conventions and its ORM |
My default for a new API is FastAPI. You declare the request body as a Pydantic model and get validation, a 422 error for bad input and interactive docs at /docs without writing any of it. Flask is still a good choice for a small service or a codebase that already uses it. I would choose Django when the client needs a back-office admin early and the team is happy to follow its conventions.
Here is a complete FastAPI endpoint:
from fastapi import FastAPI
from pydantic import BaseModel, Field
app = FastAPI()
class OrderIn(BaseModel):
product: str = Field(min_length=1)
quantity: int = Field(gt=0, le=100)
@app.post("/orders", status_code=201)
def create_order(order: OrderIn) -> dict:
return {"product": order.product, "quantity": order.quantity}
Posting {"product": "coffee", "quantity": 0} returns 422 with a body that names the field and the rule (trimmed):
{
"detail": [
{
"type": "greater_than",
"loc": ["body", "quantity"],
"msg": "Input should be greater than 0",
"input": 0
}
]
}
FastAPI CRUD with SQLAlchemy 2 and Alembic builds the full version with a database.
Stage 4: PostgreSQL with SQLAlchemy 2 and Alembic
Learn one relational database properly, and make it PostgreSQL unless your project already runs on something else. On top of it, use SQLAlchemy as the ORM and Alembic for schema migrations.
Add the ORM and a PostgreSQL driver with uv add sqlalchemy "psycopg[binary]", then point the app at the database with a URL such as DATABASE_URL=postgresql+psycopg://app:secret@localhost:5432/orders. The +psycopg part names the driver. SQLAlchemy 2.1 picks psycopg 3 for a plain postgresql:// URL, but 2.0 looks for psycopg2 there and fails with ModuleNotFoundError, so spelling it out works on both.
Many SQLAlchemy tutorials still show the 1.x style with session.query(...). The 2.0 style declares columns with type hints and builds queries with select():
class Order(Base):
__tablename__ = "orders"
id: Mapped[int] = mapped_column(primary_key=True)
product: Mapped[str] = mapped_column(String(100))
quantity: Mapped[int]
engine = create_engine(os.environ["DATABASE_URL"])
with Session(engine) as session:
stmt = select(Order).where(Order.quantity > 3)
print(stmt)
print(session.scalars(stmt).all()[0].product)
Run against PostgreSQL 17 with 2 rows (coffee ×2, tea ×5), it prints the SQL it will send and the one match:
SELECT orders.id, orders.product, orders.quantity
FROM orders
WHERE orders.quantity > :quantity_1
tea
The excerpt leaves out the imports, the Base class and a Base.metadata.create_all() call that creates the table. In a real project, Alembic owns the schema instead. alembic revision --autogenerate compares your models with the database and writes a migration file you review and commit, and alembic upgrade head applies it. The SQLAlchemy 2.0 docs and Alembic docs are good references. For indexes, transactions and the SQL that every ORM eventually produces, see Databases for app developers.
Stage 5: Test with pytest
pytest is the default test runner, and two of its features cover most API tests. A fixture provides a ready object (a client, a database session) to any test that names it as a parameter. parametrize runs one test with many inputs:
import pytest
from fastapi.testclient import TestClient
from main import app
@pytest.fixture
def client() -> TestClient:
return TestClient(app)
@pytest.mark.parametrize(
("body", "status"),
[
({"product": "coffee", "quantity": 2}, 201),
({"product": "coffee", "quantity": 0}, 422),
({"product": "", "quantity": 1}, 422),
],
)
def test_create_order(client: TestClient, body: dict, status: int) -> None:
assert client.post("/orders", json=body).status_code == status
$ uv run pytest -q
... [100%]
3 passed in 0.12s
Many tutorials install httpx for TestClient. With FastAPI 0.165, uv installs Starlette 1.10, and that combination prints a warning on every run:
StarletteDeprecationWarning: Using `httpx` with `starlette.testclient` is deprecated; install `httpx2` instead.
Putting httpx2 in the dev group, as in the pyproject.toml above, removes the warning. pytest essentials goes further into fixtures, parametrize and mocking.
Stage 6: Ship it in Docker
Package the API as a Docker image that reads its settings from environment variables: the database URL, secrets, log level. That is why the example reads os.environ["DATABASE_URL"] instead of hard-coding a connection string. The same image then runs on your laptop, in CI and on the server with different values. Inside the image, uv sync --frozen installs exactly what uv.lock says.
Building the image, running it behind a reverse proxy and wiring up CI belong to the DevOps for app developers pillar, and the steps are the same whether the image holds Python or Java.
Branch A: Automation scripts
Automation needs only stages 1 and 2, so you can start this branch early. A typical script reads arguments, works on files or calls an HTTP API, logs what it did and exits with a useful status code. Use argparse from the standard library, or Typer if you like type hints driving the CLI as they drive FastAPI. Add pathlib for files and an HTTP client such as httpx for APIs. Run it on a schedule with cron, a systemd timer or a CI scheduled job.
Give scripts a pyproject.toml too, so they still run in a year on another machine. Python automation scripts collects worked examples.
Branch B: Odoo development
Odoo is an open-source ERP written in Python, and custom modules are a steady niche if you like business software for small and medium companies. A module combines Python models on Odoo's own ORM, XML views for forms and lists, and access rights that decide which user groups can read or write each model.
I would learn plain Python and SQL first (stages 1, 2 and 4), then Odoo. Its ORM and conventions are specific to Odoo, and they are easier to pick up once you know what they abstract. The Odoo developer docs are the primary reference. The Odoo series on this site starts with your first custom Odoo module.
What can wait
These are worth learning later, when a project asks for them:
- Django internals. If your job is Django, learn Django. Otherwise one framework is enough for now.
-
asyncio internals. FastAPI runs plain
defendpoints in a thread pool, so you can write synchronous code at first. Learnasync defand the event loop when you call many slow services concurrently. - Celery and task queues, until a request really needs to hand work to a background worker.
- Kubernetes, until one container on one server is not enough.
- The data science stack (NumPy, pandas, notebooks), unless your work is data analysis.
If you also work in Java, the Java backend roadmap follows the same path with Spring Boot.
Coming in this pillar
- Python project setup with uv and pyproject.toml
- FastAPI CRUD with SQLAlchemy 2 and Alembic
- Python automation scripts
- pytest essentials: fixtures, parametrize, mocking
- Python learning path: free posts first, then paid courses
- Odoo: your first custom module,
_inheritvs_inherits, what drives the cost of a custom module, customise or configure - Spring Boot or FastAPI for your product backend
Start with stage 1: set up a Python project with uv.
Top comments (0)