Poetry
Links
Poetry
is a Python tool that facilitates dependency management and packaging. It allows developers to declare the libraries their project depends on and manages (installs/updates) them efficiently. Poetry offers a lockfile to ensure repeatable installs and can build your project for distribution, streamlining the development workflow.
Usage Examplesβ
Creating a New Projectβ
Create a new project directory with a basic structure:
poetry new my-project
Adding Dependenciesβ
Add a package as a dependency to your project:
poetry add requests
Add a development dependency (e.g., for testing or linters):
poetry add pytest --dev
Installing Dependenciesβ
Install all the dependencies specified in pyproject.toml
:
poetry install
Running Scriptsβ
Run a script or command in the context of the projectβs virtual environment:
poetry run python my_project/main.py
Managing the Virtual Environmentβ
Activate the virtual environment:
poetry shell
Deactivate the virtual environment by simply exiting the shell session.
Updating Dependenciesβ
Update specific dependencies:
poetry update requests
Update all dependencies to the latest compatible versions:
poetry update
Building and Publishingβ
Build the project for distribution:
poetry build
Publish the project to a package index (e.g., PyPI):
poetry publish --username <username> --password <password>
Listing Dependenciesβ
Show the installed dependencies and their versions:
poetry show --tree