A template for Python projects.
Includes basic project structure, a test suite, a code formatter and linter, and a dependency manager.
You need the uv package/project manager to install the dependencies.
You can get uv here.
Note
To change the Python version, change the requires-python field in pyproject.toml
and the number in .python-version.
uv will take care of the rest.
Remember to replace the placeholders in the pyproject.toml file and change/remove the LICENSE file.
Set up the environment. (Only once)
uv venv
# .venv/Scripts/activate # Windows
source .venv/bin/activate # Linux/MacOS
uv sync --link-mode=symlink # Install the dependencies, use -U to updateIf you want Pytorch (with or without CUDA), you can install it using the --extra flag.
uv sync --link-mode=symlink --extra=torch-cpu # for CPU only
uv sync --link-mode=symlink --extra=torch-cu124 # for CUDA supportYou can add other dependencies use uv add. The following example adds a valid kernel for Jupyter notebooks in VSCode.
uv add ipykernel # Similar to pip install ipykernelTo run any script, append uv run before the python command. (If the environment is inactive)
uv run python src/hello.pyRun tests:
uv run python -m unittest discoverGet rid of temporary files: (Use with caution)
git clean -fdX -n # Remove the -n flag to actually delete the filesWe have ruff for code formatting and linting.
Install the VSCode extension
and enable Format on Save for a better experience.
To fix imports:
uv run ruff check --select I --fix # Sort imports
uv run ruff check --select F401 --fix # Remove unused importsTo check for linting errors:
uv run ruff check # Use --fix to fix the errorsTo format the code:
uv run ruff format