## Creation
Move into the workspace directory in which you want to create your new project:
```
cd ~/work/src/git
```
Create a new project using Poetry:
```
poetry new PROJECT_NAME
```
Move into the project directory Poetry just created
```
cd PROJECT_NAME
```
And set up git:
```
git init
git add *
```
It typically is worth to ignore the `__pycache__` directories:
```
echo __pycache__ >> .gitignore
git add .gitignore
```
## Python Version
Check the `python` version in `pyproject.toml`, if that matches what you expect and use the desired Python version:
```
export PYTHON_VERSION=TODO
```
```
pyenv local $PYTHON_VERSION
poetry env use $PYTHON_VERSION
```
If you want to omit the Python version information or avoid leaking pyenv configuration files, ignore the `pyenv` Python version file in Git:
```
echo .python-version >> .gitignore
git add .gitignore
```
To check the system version used by your Poetry environment, you can review `poetry env info`.
Note that Poetry by default uses the Python executable which was used to install it.
## Dependencies
*Optionally*, add your main dependencies for the project using `poetry add`, for example:
```
poetry add fastapi "uvicorn[standard]"
```
Add your development dependencies. Strongly suggested minimal set; Notice that mypy, black, and ruff can also be handled by pre-commit and don't need to be configured here:
```
poetry add --group dev pytest
```
Or, *optionally*:
```
poetry add --group dev pytest mypy black ruff "bandit[toml]"
```
Now you can install the configured setup; run:
```
poetry install
git add poetry.lock
git add pyproject.toml
```
## Commit
Commit the initial setup:
```
git commit -a -m "Project setup."
```
You can now work in this project environment using
```
poetry shell
```
## Optional: direnv
To automatically drop into the Poetry shell every time you enter the project directoy, create the following `.envrc`:
```shell
cat << ENVRC > .envrc
layout poetry
poetry shell
ENVRC
```
For `layout poetry` to work, you must have [configured direnv for Poetry](Configure%20direnv%20for%20Poetry.md).