Full Project Lifecycle with Poetry
Manage Python project dependencies, virtual environments, versioning, and publishing with Poetry's declarative pyproject.toml workflow.
Prerequisites
- -Python 3.8+ installed
- -pipx or uv installed (recommended for Poetry install)
Steps
Install Poetry
Install Poetry in an isolated environment using pipx. This prevents Poetry's own dependencies from conflicting with your projects.
Alternatively use: curl -sSL https://install.python-poetry.org | python3 -
Do not install Poetry with pip into a project virtualenv. It should be installed globally via pipx or the official installer.
Create a new project
Scaffolds a new project with pyproject.toml, a package directory, and a tests directory. The generated structure follows Python packaging best practices.
Add production dependencies
Adds packages to the [tool.poetry.dependencies] section and installs them. The poetry.lock file is updated automatically.
Add development dependencies
Adds packages to the dev dependency group. These are excluded when building distribution packages.
You can create custom groups like --group docs for documentation tools.
Run commands inside the environment
Execute any command within the project's virtual environment without manually activating it.
Build and publish the package
Bump the version, build source and wheel distributions, and preview a publish to PyPI. Remove --dry-run when ready to publish for real.
You need a PyPI account and API token configured via 'poetry config pypi-token.pypi <token>' before you can publish.
Full Script
FAQ
Discussion
Loading comments...