Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ABohynDOE/a5dfb647a5988fdf2a359d68bb9404b0 to your computer and use it in GitHub Desktop.

Select an option

Save ABohynDOE/a5dfb647a5988fdf2a359d68bb9404b0 to your computer and use it in GitHub Desktop.
Python Poetry Cheatsheet

Create a new project

poetry new <project-name>

Add a new package

Use -D or --dev to add it to the dev dependencies

potry add <package>

Remove a package

Use -D or --dev to remove a package added to dependencies

poetry remove <package>

Update a package

Updated according to versions in the pyproject.toml file

poetry update <package>

If no <package> is specified, all packages are updated

Show dependencies

poetry show

Get venv path

To obtain the path to the python executable

poetry run which python

To have all information about the venv use

poetry env info

List all venv

poetry env list

Delete a venv

The venv name is listed with all venv

poetry env remove <venv-name>

Run a file

Python file
poetry run python main.py
Tests using pytest

-v and -q options can be used to add verbosity or run the tests qitely.

poetry run pytest . -v

All commands can be used inside venv by removing the poetry run part when using the shell. To spawn the venv shell use

poetry shell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment