Poetry — Python Packaging and Dependency Management Made Easy
Poetry is a comprehensive tool for Python dependency management and packaging. It handles virtual environments, dependency resolution, lockfiles, and publishing to PyPI — all through a single, intuitive command-line interface.
What it is
Poetry is a comprehensive tool for Python dependency management and packaging. It handles virtual environment creation, dependency resolution with a lockfile, and package publishing to PyPI -- all through a single CLI. It replaces the fragmented workflow of pip + virtualenv + setuptools + twine.
The tool targets Python developers, library authors, and teams who want reproducible builds and a modern dependency management experience similar to npm or cargo.
How it saves time or tokens
Poetry resolves dependency conflicts at install time and locks exact versions in poetry.lock. This eliminates 'works on my machine' issues and makes CI builds deterministic. The pyproject.toml file consolidates project metadata, dependencies, and build config into one place.
How to use
- Install Poetry:
curl -sSL https://install.python-poetry.org | python3 -. - Create a new project:
poetry new my-projector add Poetry to an existing project:poetry init. - Add dependencies:
poetry add requests flaskand Poetry handles resolution, lockfile, and virtual environment.
Example
# Install Poetry
curl -sSL https://install.python-poetry.org | python3 -
# Create a new project
poetry new my-api
cd my-api
# Add dependencies
poetry add fastapi uvicorn
poetry add --group dev pytest black mypy
# Run in the virtual environment
poetry run python -m uvicorn main:app --reload
# Build and publish to PyPI
poetry build
poetry publish
Related on TokRepo
- AI Tools for Coding -- developer productivity tools
- Automation Tools -- workflow automation for development teams
Common pitfalls
- Poetry creates a virtual environment by default. If you use Docker, set
poetry config virtualenvs.create falseto install directly into the system Python. - The lockfile (
poetry.lock) should be committed to git for applications but omitted for libraries. This matches the npm convention of package-lock.json. - Poetry's dependency resolver can be slow for projects with many transitive dependencies. Use
--no-updatewhen adding a single package to avoid re-resolving the entire tree.
Frequently Asked Questions
pip installs packages but does not resolve conflicts or create lockfiles. Poetry handles resolution, locking, virtual environments, and publishing. It replaces the pip + virtualenv + setuptools toolchain with a single unified tool.
No. Poetry requires Python 3.8 or later. It is designed for modern Python development and uses pyproject.toml, which is a Python 3 standard.
Yes. In Dockerfiles, install Poetry, copy pyproject.toml and poetry.lock, run poetry install --no-dev, then copy your source code. Set virtualenvs.create false to avoid unnecessary virtual environments inside containers.
Yes. Poetry uses its own build backend. You define metadata in pyproject.toml and run poetry build to create sdist and wheel distributions. Poetry publish uploads directly to PyPI.
Poetry supports named dependency groups like dev, test, and docs. Use poetry add --group dev pytest to add a dev-only dependency. Groups can be installed or excluded individually with poetry install --without dev.
Citations (3)
- Poetry GitHub— Python dependency management and packaging tool
- Poetry Documentation— Deterministic builds with lockfile resolution
- Poetry pyproject.toml Docs— pyproject.toml as the single project configuration file
Related on TokRepo
Discussion
Related Assets
NAPI-RS — Build Node.js Native Addons in Rust
Write high-performance Node.js native modules in Rust with automatic TypeScript type generation and cross-platform prebuilt binaries.
Mamba — Fast Cross-Platform Package Manager
A drop-in conda replacement written in C++ that resolves environments in seconds instead of minutes.
Plasmo — The Browser Extension Framework
Build, test, and publish browser extensions for Chrome, Firefox, and Edge using React or Vue with hot-reload and automatic manifest generation.