Interview Prep/Build Tools (Java, Node.js, Python, .NET)/Python builds (pip, venv, requirements.txt)
What are Poetry and uv?
IntermediateConceptPython builds (pip, venv, requirements.txt)
Answer
Short answer
Both are tools that manage Python dependencies with a lockfile and handle virtual environments for you. Poetry (poetry.lock) has been popular for years. uv (uv.lock), from Astral, is a very fast newer tool that replaces pip, pip-tools, venv and Poetry, and installs packages in seconds.
Common commands
| Task | Poetry | uv |
|---|---|---|
| Add a package | poetry add fastapi |
uv add fastapi |
| Install from lock (CI) | poetry install --no-root --only main |
uv sync --frozen --no-dev |
| Run a command in the env | poetry run pytest |
uv run pytest |
| Update the lock | poetry lock |
uv lock |
Dockerfile with uv
FROM python:3.12-slim
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv
WORKDIR /app
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev
COPY . .
CMD ["uv", "run", "uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
What to say in the interview
"Poetry and uv both give lockfile-based, reproducible installs and manage venvs. uv is much faster, which noticeably cuts CI time. Whichever the repo uses, CI installs from the lockfile in frozen mode."
All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Python apps: pip, venv & requirements.txt
More on Python builds (pip, venv, requirements.txt)
How do you install dependencies and run a Python application?BeginnerWhat is a Python virtual environment and why do we need it?BeginnerWhat is requirements.txt and how do you pin versions?BeginnerHow do you run a Flask application in development and in production?BeginnerWhat is gunicorn and how many workers should you run?BeginnerWhat is the difference between WSGI and ASGI?Intermediate