Poetry
Poetry
- Python Dependency Management
Overview
Poetry is a modern tool for dependency management and packaging in Python. It provides a deterministic way to manage libraries, virtual environments, and project metadata in a single `pyproject.toml` file.
Why use Poetry?
- Dependency Resolution: It has a robust solver that handles conflicts (Version Hell) gracefully.
- Lockfile: Generates `poetry.lock` to ensure all developers (and prod) use the exact same package versions.
- Packaging: Makes publishing to PyPI trivial (`poetry publish`).
Basic Commands
**Start new project**
poetry new my-app
**Add a library**
poetry add pandas
**(Automatically updates pyproject.toml, installs to venv, updates lockfile)**
**Developer Tools**
poetry add --group dev black pytest
**Run**
poetry run python main.py
**Shell**
poetry shellvs Pip
- Pip: Just installs. Doesn't lock dependencies effectively (recursive dependencies often float).
- Poetry: Full project management.
It is the closest thing Python has to `npm` or `cargo`.