Poetry: Simplifying Python Packaging and Dependency Management
Poetry is a powerful tool designed to make managing and declaring dependencies in Python projects straightforward and efficient. It ensures that the correct versions of dependencies are installed across different environments, thus maintaining a consistent development experience.
What is Poetry?
Poetry aims to simplify Python projects by replacing common files like setup.py
, requirements.txt
, setup.cfg
, MANIFEST.in
, and Pipfile
with a single, comprehensive pyproject.toml
file. This unified format supports various configurations, such as package metadata, dependencies, scripts, and more.
Here's an example of how a pyproject.toml
file can be structured:
[tool.poetry]
name = "my-package"
version = "0.1.0"
description = "The description of the package"
license = "MIT"
authors = ["Sébastien Eustace <[email protected]>"]
repository = "https://github.com/python-poetry/poetry"
homepage = "https://python-poetry.org"
readme = ["README.md", "LICENSE"]
keywords = ["packaging", "poetry"]
[tool.poetry.dependencies]
python = ">=3.8"
aiohttp = "^3.8.1"
requests = { version = "^2.28", extras = ["security"] }
tomli = { version = "^2.0.1", python = "<3.11", allow-prereleases = true }
cleo = { git = "https://github.com/python-poetry/cleo.git", branch = "main" }
pendulum = { version = "^2.1.2", optional = true }
[tool.poetry.group.dev.dependencies]
pytest = "^7.1.2"
pytest-cov = "^3.0"
[tool.poetry.group.docs]
optional = true
[tool.poetry.group.docs.dependencies]
Sphinx = "^5.1.1"
[tool.poetry.scripts]
my-script = "my_package:main"
Installation and Usage
Poetry can be installed using multiple methods, with the simplest being a script available at install.python-poetry.org. For comprehensive installation guidance, including alternative methods and best practices for continuous integration (CI), users can refer to the full installation documentation.
Comprehensive Documentation
Detailed documentation is provided for both the current version of Poetry and for development branches. This can be accessed via the official website.
Getting Involved
As a complex and ever-evolving project, Poetry welcomes contributors. There's a dedicated list of suggested issues suitable for newcomers, and the contributing documentation offers helpful advice for those looking to get involved.
Additional Resources
- Releases for the latest versions
- The Issue Tracker for reporting bugs or suggesting features
- Discord for community support and discussions
Related Projects
Poetry's ecosystem includes several related projects:
[poetry-core](https://github.com/python-poetry/poetry-core)
: The PEP 517 build system used by Poetry.[poetry-plugin-export](https://github.com/python-poetry/poetry-plugin-export)
: Tool to export Poetry projects to formats such asrequirements.txt
.[poetry-plugin-bundle](https://github.com/python-poetry/poetry-plugin-bundle)
: Utility to install Poetry projects into formats like virtual environments.[install.python-poetry.org](https://github.com/python-poetry/install.python-poetry.org)
: The official installation script for Poetry.[website](https://github.com/python-poetry/website)
: The codebase for the official Poetry website and blog.
In summary, Poetry revolutionizes Python project management by offering a streamlined and powerful approach to handling dependencies and project configuration.