Python

Poetry CLI

Poetry commands for Python dependency management and packaging.

31 commands
Windows MacOS Linux
#package-manager #dependency

Project Management

Create a new Python project with structure
poetry new myproject
Initialize poetry in an existing project
poetry init
Validate pyproject.toml structure
poetry check
Generate or update the lock file
poetry lock
Regenerate lock file without updating deps
poetry lock --no-update

Dependencies

Add a package as a dependency
poetry add requests
Add a dev dependency
poetry add pytest --group dev
Add with version constraints
poetry add "numpy>=1.24,<2.0"
Remove a dependency
poetry remove requests
Install all dependencies from lock file
poetry install
Install without dev dependencies
poetry install --no-dev
Update all dependencies to latest allowed
poetry update
Show all installed packages
poetry show

Virtual Environments

Use a specific Python version
poetry env use python3.11
Show active environment information
poetry env info
List all virtual environments
poetry env list
Remove a virtual environment
poetry env remove python3.11
Spawn a shell in the virtual environment
poetry shell
Run a command in the virtual environment
poetry run python main.py

Building & Publishing

Build source and wheel distributions
poetry build
Publish package to PyPI
poetry publish
Build and publish in one step
poetry publish --build
Publish to a private repository
poetry publish -r private

Configuration

List all configuration settings
poetry config --list
poetry config virtualenvs.in-project true # Create virtualenv in project directory
Add a private repository
poetry config repositories.private https://pypi.example.com
Add a package source
poetry source add private https://pypi.example.com
Set PyPI authentication token
poetry config pypi-token.pypi my-token

Quick Commands

Add a package as a project dependency and update the lock file
poetry add requests
Install all dependencies from the lock file into the virtual environment
poetry install
Build source distribution and wheel packages for publishing
poetry build