What Is Poetry? Python Dependency and Packaging Explained
Poetry is a Python tool that manages dependencies, virtual environments, and packaging from a single pyproject.toml, with a lockfile for reproducible installs.
Poetry brings the lockfile-driven, all-in-one workflow that JavaScript and Rust developers enjoy to Python. Instead of juggling requirements files, setup.py, and a separate virtualenv tool, you describe everything in pyproject.toml and let Poetry resolve, lock, install, and publish.
What Poetry is
Poetry is a dependency manager and build tool for Python projects. It reads and writes the standard pyproject.toml, resolves a complete dependency graph, and records exact versions in poetry.lock. It also creates and manages a virtual environment for the project automatically.
How it works
You declare dependencies with "poetry add", and Poetry resolves compatible versions and writes them to poetry.lock. "poetry install" then installs exactly what the lockfile specifies into a managed virtual environment. Because the lockfile captures the full resolved graph, every machine and CI runner gets an identical environment.
A usage example
The common flow is add, install, run.
# add a dependency (updates pyproject.toml and poetry.lock)
poetry add requests
# install exactly from the lockfile
poetry install --no-interaction
# run a command inside the managed venv
poetry run pytestRole in CI/CD
In CI, "poetry install --no-interaction" reproduces the locked environment, and "poetry run" executes tests or builds inside it. Caching Poetry virtualenvs or its cache directory between runs avoids re-resolving and re-downloading. The lockfile makes CI builds deterministic, which is the main reason teams adopt Poetry over loose requirements files.
Alternatives
pip with a pinned requirements file is the minimal baseline. PDM is a similar standards-based manager. uv is a fast newcomer that can resolve, lock, and install. Poetry stands out for its mature, integrated workflow covering dependencies, environments, and publishing.
Key takeaways
- Poetry manages dependencies, environments, and packaging from pyproject.toml.
- poetry.lock pins the full resolved graph for reproducible installs.
- Use "poetry install --no-interaction" in CI and cache the virtualenv.