Template repo for Python projects
uv and pyproject.toml
are used for Python package setup and dependency management.
- Clone the project using git
- Create the venv:
uv sync
. This will create a virtual environment in the.venv
directory, using python specified in the.python-version
file. By default, this will include thedev
dependencies. - Activate the venv:
source .venv/bin/activate
(Linux or MacOS) - Install the project in editable mode:
uv pip install -e .
- Install the pre-commit hooks:
pre-commit install
python-dotenv
is used to manage environment variables. These are stored in a .env
file in the project root.
.env.example
is provided as a template for the .env
file.
Dependencies are defined within requirements.in
and requirements-dev.in
files.
These are then compiled into requirements.txt
and requirements-dev.txt
files using compile-reqs
command.
For best compatibility with and without uv
, dependencies from requirements.txt
and requirements-dev.txt
are also
added to the pyproject.toml
file using uv add -r requirements.txt
and uv add -r requirements-dev.txt --dev
.
This allows us to use uv sync
to install the dependencies from the pyproject.toml
file into the virtual environment.
As the uv
ecosystem matures, the requirements.txt
files may be phased out in favor of the pyproject.toml
file.
- Add the package to the relevant
.in
file - Run
compile-reqs
(installed as project script) to compile the requirements files - Run
uv add -r requirements.txt
and/oruv add -r requirements-dev.txt --dev
, to update thepyproject.toml
file with the new dependencies. - Run
uv sync
to update the virtual environment with the new dependencies.
The complete list of installed packages can be shown using uv tree
.
Pre-commit hooks are used to enforce code quality and style standards.
These are defined in the .pre-commit-config.yaml
file.
To install the pre-commit hooks, run pre-commit install
.