Skip to content

Instantly share code, notes, and snippets.

@rendicahya
Last active August 16, 2025 13:26
Show Gist options
  • Save rendicahya/a5a8699b48bae667678de3ca3e284d6f to your computer and use it in GitHub Desktop.
Save rendicahya/a5a8699b48bae667678de3ca3e284d6f to your computer and use it in GitHub Desktop.
Poetry Cheatsheet

Poetry Cheatsheet

Project Management

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

Dependency Management

  • Install package
poetry add <package-name>
poetry add <package-name>==<version>
poetry add <package-name>@^<version>
  • Install all dependencies from pyproject.toml and poetry.lock
poetry install
  • List all packages
poetry show
poetry show --tree
poetry show --outdated
poetry show --latest
  • Update dependencies
poetry update
poetry update <package>
  • Remove package
poetry remove <package-name>
  • Lock project dependencies
poetry lock

Virtual Environments

  • Activate virtual environment
poetry shell
  • Execute command within virtual environment
poetry run <command>
poetry run python <python-script>
  • List all virtual environments
poetry env list
  • Display virtual environment information
poetry env info
  • Remove virtual environment
poetry env remove <env-name>

Scripts

  • Edit pyproject.toml:
[tool.poetry.scripts]
my-cli = "my_project.cli:main"
  • Add my_project/cli.py:
def main():
    print("Hello from my_project!")

if __name__ == "__main__":
    main()
  • Run:
poetry run my-cli

Packaging and Publishing

  • Build source and wheel distributions
poetry build
  • Publishe package to a repository
poetry publish
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment