Poetry Cheat Sheet for Developers¶
Introduction to Poetry¶
Poetry is a dependency management and packaging tool for Python that aims to simplify and enhance the development process. It offers features for managing dependencies, virtual environments, and building and publishing Python packages.
Virtual Environments with Poetry¶
Poetry manages virtual environments for your projects to ensure clean and isolated development environments.
Creating a Virtual Environment¶
Activating the Virtual Environment¶
Alternatively you can source the environment settings in the current shell
for powershell users this would be
Deactivating the Virtual Environment¶
When using poetry shell
When using the activate
script
Dependency Management¶
Poetry uses the pyproject.toml
file to manage dependencies. Add new
dependencies to this file and update existing ones as needed.
Adding a Dependency¶
Adding a Development Dependency¶
Removing a Dependency¶
Updating Dependencies¶
Running Tasks with Poetry¶
Poetry provides a way to run scripts and commands without activating the virtual environment explicitly.
Running a Command¶
Running a Script¶
Building and Publishing with Poetry¶
Poetry streamlines the process of building and publishing Python packages.
Building the Package¶
Publishing the Package¶
Using Extras¶
Extras allow you to specify additional dependencies based on project requirements.
Installing with Extras¶
for example
Managing Development Dependencies¶
Development dependencies are useful for tasks like testing, linting, and documentation generation.