| name | poetry |
| description | Manage Python projects with Poetry for dependency management, packaging, and publishing. Use when users want to create pyproject.toml files, add/remove dependencies, configure virtual environments, build packages, or publish to PyPI. Generates working configuration files and shell commands. |
Poetry Python Package Manager Skill
Manage Python projects using Poetry for dependency management, virtual environments, packaging, and publishing. Follow Python packaging standards (PEP 621, PEP 735) for maximum compatibility.
Version: Poetry 2.x | Requires: Python 3.9+
Workflows
Determine which workflow to follow based on the user's request:
Starting a new project? → Follow "New Project Setup" below
Managing dependencies? → Follow "Dependency Management" below
Building or publishing? → Follow "Build & Publish" below
Configuring pyproject.toml? → See references/pyproject-toml.md for complete reference
Need a specific CLI command? → See references/cli-reference.md for all commands
New Project Setup
-
Determine project type:
- Library/application to distribute → Use package mode (default)
- Dependency management only → Use non-package mode (
package-mode = false)
-
Create the project:
poetry new my-package
poetry init
-
Generate a pyproject.toml with at minimum:
[build-system]
requires = ["poetry-core>=2.0.0,<3.0.0"]
build-backend = "poetry.core.masonry.api"
[project]
name = "my-package"
version = "0.1.0"
description = "A Python package"
readme = "README.md"
requires-python = ">=3.9"
license = "MIT"
authors = [{ name = "Your Name", email = "you@example.com" }]
dependencies = []
For non-package mode, add [tool.poetry] with package-mode = false and omit name/version from [project].
See references/pyproject-toml.md for full configuration options including classifiers, entry points, URLs, and tool-specific sections (pytest, ruff, mypy, etc.).
-
Install and create the virtual environment:
poetry install
Dependency Management
Use PEP 440 constraints in [project.dependencies] for standard dependencies. Use [tool.poetry.dependencies] only for Poetry-specific features (caret ^/tilde ~ operators, git/path sources).
poetry add requests
poetry add "requests>=2.28.0"
poetry add pytest --group test
poetry add ./local-package
poetry add git+https://github.com/...
poetry remove requests
poetry update
poetry lock
Organize dependencies into groups:
- Main →
[project.dependencies] — always installed
- Optional groups →
[project.optional-dependencies] or [tool.poetry.group.<name>.dependencies] — installed with --with
See references/pyproject-toml.md for version constraint syntax, environment markers, git/path/URL dependencies, and extras.
See references/cli-reference.md for all add, remove, update, install, and sync options.
Build & Publish
- Validate configuration:
poetry check
- Build:
poetry build
- Configure credentials:
poetry config pypi-token.pypi <token>
- Publish:
poetry publish
For private repositories, configure the repository first:
poetry config repositories.private https://pypi.example.com/simple/
poetry publish --repository private
See references/cli-reference.md for all build/publish/config options.
Best Practices
- Commit poetry.lock for applications (reproducible builds)
- Consider not committing poetry.lock for libraries (let users resolve)
- Use dependency groups to organize dev, test, docs dependencies
- Pin major versions with
>=X.Y,<X+1 for stability
- Run
poetry check before commits to validate configuration
- Use
poetry sync in CI for exact reproducibility
Pre-commit Hooks
repos:
- repo: https://github.com/python-poetry/poetry
rev: '2.0.0'
hooks:
- id: poetry-check
- id: poetry-lock
args: ["--check"]