Skip to content

Instantly share code, notes, and snippets.

@rendicahya
Last active May 9, 2026 13:02
Show Gist options
  • Select an option

  • Save rendicahya/a5a8699b48bae667678de3ca3e284d6f to your computer and use it in GitHub Desktop.

Select an option

Save rendicahya/a5a8699b48bae667678de3ca3e284d6f to your computer and use it in GitHub Desktop.
Poetry & uv Cheatsheet

Poetry & uv Cheatsheet

Installation

Task Poetry uv
Install via official installer curl -sSL https://install.python-poetry.org | python3 - curl -LsSf https://astral.sh/uv/install.sh | sh
Install via pip pip install poetry pip install uv
Verify installation poetry --version uv --version

Typical Workflow

Step Poetry uv
Create project poetry new my-project uv init my-project
Enter project directory cd my-project cd my-project
Add dependencies poetry add torch lightning uv add torch lightning
Install/sync environment poetry install uv sync
Run application poetry run python train.py uv run python train.py
Add dev dependencies poetry add --group dev pytest black uv add --dev pytest black
Run tests poetry run pytest uv run pytest
Build package poetry build uv build

Project Management

Task Poetry uv
Create new project poetry new <project-name> uv init <project-name>
Initialize project in current directory poetry init uv init
Display configuration poetry config --list uv config list

Dependency Management

Task Poetry uv
Add package poetry add <package-name> uv add <package-name>
Add specific version poetry add <package-name>==<version> uv add <package-name>==<version>
Add compatible version poetry add <package-name>@^<version> uv add '<package-name>^<version>'
Install dependencies poetry install uv sync
List installed packages poetry show uv pip list
Show dependency tree poetry show --tree uv tree
Show outdated packages poetry show --outdated uv pip list --outdated
Update all dependencies poetry update uv lock --upgrade + uv sync
Update specific package poetry update <package> uv add <package> --upgrade-package <package>
Remove package poetry remove <package-name> uv remove <package-name>
Lock dependencies poetry lock uv lock

Virtual Environments

Task Poetry uv
Activate virtual environment poetry shell source .venv/bin/activate (Linux/macOS), .venv\\Scripts\\activate (Windows)
Run command in virtual environment poetry run <command> uv run <command>
Run Python script poetry run python <script.py> uv run python <script.py>
List environments poetry env list uv venv --help
Show environment info poetry env info uv pip list / inspect .venv
Create virtual environment (automatic) uv venv
Remove virtual environment poetry env remove <env-name> Delete .venv manually

Scripts

Task Poetry uv
Define CLI entrypoint in pyproject.toml [tool.poetry.scripts]
my-cli = "my_project.cli:main"
[project.scripts]
my-cli = "my_project.cli:main"
Run CLI command poetry run my-cli uv run my-cli

Example my_project/cli.py:

def main():
    print("Hello from my_project!")

if __name__ == "__main__":
    main()

Packaging and Publishing

Task Poetry uv
Build distributions poetry build uv build
Publish package poetry publish uv publish

Python Version Management

Task Poetry uv
Specify Python version poetry env use <python> uv python install <version>
Install Python External tool required uv python install 3.12
List available Python versions External tool required uv python list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment