This is a short cheat-sheet with some of the most common commands to be used when managing a [[Python]] project with [[Poetry]]
> [!Warning]
> If you have just installed Poetry, there is a fair chance that now is the perfect moment to configure it to create the virtual environments in each project's folder (in a subfolder called `.venv/`, which can be added to the `.gitignore` file.
> ```bash
> poetry config virtualenvs.in-project true
> ```
To create set up a new project you can use:
```bash
# If you want to create a new folder, from scratch
poetry new project-name
# If the project exists and you want to set up poetry
poetry init
```
Poetry defines all its settings in a `pyproject.toml`, a file that is not exclusive to Poetry but actually complies with [PEP 518](https://peps.python.org/pep-0518/). In this file, all dependencies and module info is gathered. To add a new dependency:
```bash
# If it is a runtime dependency
poetry add pandas
# If it is a development dependency
poetry add -D black
```
To update the lockfile and install all dependencies, run:
```shell
poetry install
```