Skip to the page

Python in production · mid

Lock files, uv, packaging and upgrading Python

A service locks every dependency, including transitive ones. A library declares ranges. Teams choose pip, Poetry or uv, publish internal packages to a private index, and upgrade Python on a plan.

The notes

What you must know

  • A requirements.txt with only direct dependencies and open ranges resolves fresh on every build, so a new major version of a transitive package can break a deploy. First redeploy the old image; then diff pip freeze between the two images.
  • Lock everything with exact versions and hashes: pip-tools (pip-compile --generate-hashes), Poetry (poetry.lock) or uv (uv.lock; uv sync --locked fails if the lock is out of date). PEP 751 defines a standard pylock.toml.
  • Applications lock; libraries declare ranges. Build once and promote the same image. Dependabot or Renovate open update pull requests that CI tests.
  • pip with venv is the base but needs pip-tools for a real lock. Poetry 2.x supports the standard [project] table. uv is written in Rust, is very fast, installs Python versions and has uv.lock, uv sync and uv run. One tool for the whole team matters more than which one.
  • In the repo: pyproject.toml (project metadata, requires-python, dependency groups), the committed lock file, .python-version, and Ruff and type-checker config. Docker copies the lock file first so the dependency layer is cached.
  • Internal library: pyproject.toml, a build backend (hatchling, setuptools, poetry-core or uv_build), a src layout, py.typed, wheels built in CI and published to a private index. Use the private index as the only index to avoid dependency confusion. Do not copy the folder or use a submodule.
  • Versions (checked 21 Nov 2026 in facts.md): 3.9 ended 31 Oct 2025 and 3.10 on 1 Oct 2026; 3.11 to 3.13 get security fixes only; 3.14 gets bug fixes; 3.15 came out on 9 Oct 2026. Target 3.14 now and move to 3.15 when every dependency has wheels.
  • Upgrade steps: check dependency support and wheels, read What's New for each release, upgrade libraries first on the old version, run tests with -W error::DeprecationWarning, use Ruff pyupgrade rules, run a CI matrix, canary a few servers and keep the old image for rollback. Old pins (an old NumPy) may have no wheels for new Python.

The red pen

Common traps: mistake → fix

  • Mistake: pip install --upgrade everything fixes a broken deploy

    Fix: it changes many things at once; lock and test updates.

  • Mistake: Delete the upper bounds to fix a conflict

    Fix: that makes builds less repeatable.

  • Mistake: Upgrade Python and every library in one change

    Fix: split it so a failure has one cause.

  • Mistake: Put exact pins in a library

    Fix: libraries declare ranges; applications lock.

Easy to hard

Questions interviewers ask, easy to hard

  1. Nothing changed in our code but the deploy fails with an ImportError. What happened?
  2. pip, Poetry or uv for a new service? What goes in the repo?
  3. How do you make a lock file fail CI when it is stale?
  4. Four teams copy the same common_utils folder. How do you turn it into a package?
  5. Which Python version do you target for a service on 3.9, and how do you roll it out?

Practise

Practise with these questions

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview