Python Poetry Cheat Sheet
Project setup, dependency management, virtual environments, and publishing workflow using Poetry as an all-in-one Python packaging tool.
1 PageBeginnerFeb 14, 2026
Project Setup
Initialize a new project or adopt Poetry in an existing one.
bash
poetry new myproject # scaffold a new project with src layoutcd myprojectpoetry init # interactively create pyproject.toml in an existing dirpoetry check # validate pyproject.tomlpoetry env info # show the active virtualenv's details
Managing Dependencies
Add, remove, and update packages; Poetry updates pyproject.toml and the lockfile.
bash
poetry add requests # add a runtime dependencypoetry add pytest --group dev # add a dev-only dependency (groups)poetry add "django>=4.2,<5.0" # version constraintpoetry remove requests # remove a dependencypoetry update # update all deps within constraintspoetry update requests # update just one packagepoetry show --tree # show dependency treepoetry lock # regenerate poetry.lock without installing
Running & Environments
Poetry manages an isolated virtualenv per project by default.
bash
poetry install # install all deps from poetry.lockpoetry install --no-dev # (legacy) or: poetry install --only mainpoetry install --sync # remove packages not in the lockfilepoetry run python script.py # run inside the project's venvpoetry run pytest # run a tool inside the venvpoetry shell # spawn a subshell with the venv activatedpoetry env use python3.12 # pin the interpreter version
Building & Publishing
Build sdist/wheel and publish to PyPI.
bash
poetry build # produce dist/*.whl and dist/*.tar.gzpoetry config pypi-token.pypi <token> # store a PyPI API tokenpoetry publish # build (if needed) and upload to PyPIpoetry publish --build # explicit build + publish in one steppoetry version patch # bump 1.2.3 -> 1.2.4 in pyproject.toml
pyproject.toml Sections
Key tables Poetry reads to configure the project.
- [tool.poetry]- name, version, description, authors, license
- [tool.poetry.dependencies]- runtime dependencies incl. python version constraint
- [tool.poetry.group.dev.dependencies]- named dependency groups (dev, test, docs, ...)
- [tool.poetry.scripts]- console-script entry points installed as CLI commands
- [build-system]- requires = ["poetry-core"], required for PEP 517 builds
- poetry.lock- pinned, hashed dependency graph; commit this to version control
Pro Tip
Always commit poetry.lock alongside pyproject.toml — it's what gives every machine and CI run the exact same resolved dependency graph, not just versions satisfying your constraints.
Was this cheat sheet helpful?
Explore Topics
#PythonPoetry#PythonPoetryCheatSheet#Programming#Beginner#ProjectSetup#ManagingDependencies#RunningEnvironments#BuildingPublishing#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech
Professional Web Designing Services
- Responsive Websites
- E-commerce Solutions
- SEO Friendly Design
- Fast & Secure
- Support & Maintenance