A consistent, feature-rich template for Python projects. Use this as a starting point for new packages to get batteries-included tooling out of the box.
| Feature | Tool |
|---|---|
| Build & environments | Hatch with hatch-pip-compile |
| Linting & formatting | Ruff |
| Testing | pytest + coverage |
| Type checking | mypy |
| Documentation | MkDocs Material + mkdocstrings |
| Containerization | Multi-stage Dockerfile (dev / hatch / prod) |
| CI/CD | GitHub Actions with Dependabot |
| Dev environment | Dev Container for VS Code / Codespaces |
| Git hygiene | pre-commit hooks |
pip install python-templateThe template ships with an example CLI entry point:
python-template --version
python-template example "hello world"from python_template import example
result = example("hello")Prerequisites: Python 3.9+ and Hatch.
git clone https://github.com/LavLabInfrastructure/python-template.git
cd python-template
pip install hatchOptionally install pre-commit hooks:
pip install pre-commit
pre-commit installRun these directly or use the provided Makefile shortcuts (e.g. make test, make lint).
| Task | Command |
|---|---|
| Run tests | hatch run test:test |
| Tests + coverage | hatch run test:cov |
| Lint | hatch run lint:check |
| Format | hatch run lint:format |
| Auto-fix lint | hatch run lint:fix |
| Format + fix + lint | hatch run lint:all |
| Type check | hatch run types:check |
| Build docs | hatch run docs:build-docs |
| Serve docs | hatch run docs:serve-docs |
| Build wheel | hatch build |
| Clean artifacts | make clean |
# Run tests via Docker
docker build --target hatch -t myapp:hatch .
docker run --rm -e HATCH_ENV=test myapp:hatch cov
# Production image (just the installed wheel)
docker build --target prod -t myapp:prod .python-template/
├── src/
│ └── python_template/ # Package source
│ ├── __init__.py # Public API & version export
│ ├── __about__.py # Version string
│ ├── cli.py # CLI entry point (thin wrapper)
│ ├── example.py # Example library module
│ └── py.typed # PEP 561 marker
├── tests/
│ ├── conftest.py # Shared pytest fixtures
│ └── test_example.py # Example tests
├── docs/ # MkDocs source files
├── requirements/ # Locked deps (auto-generated by hatch-pip-compile)
├── .devcontainer/ # Dev container config
├── .github/
│ ├── workflows/ # CI workflows (build, test, lint)
│ └── dependabot.yml # Auto-update deps + actions + Docker
├── pyproject.toml # All project & tool configuration
├── Dockerfile # Multi-stage build
├── Makefile # Dev shortcuts
├── mkdocs.yml # Docs config
├── .pre-commit-config.yaml # Pre-commit hooks
├── .editorconfig # Editor consistency
└── .gitignore
This template follows a library-first approach:
- All logic lives in importable modules under
src/python_template/. - The CLI (
cli.py) is a thinargparsewrapper that delegates to library functions. - Tests call library functions directly — never through the CLI.
This keeps your code reusable whether it's called from the command line, another package, a notebook, or an API.
- Click Use this template on GitHub (or clone and reinitialize).
- Rename
src/python_template/to your package name. - Find-and-replace
python-template→ your project name andpython_template→ your package name. - Update
pyproject.tomlwith your metadata (author, description, dependencies). - Update
LICENSE.txtif needed. - Delete
example.pyandtest_example.pyonce you have real code.
See CONTRIBUTING.md for development guidelines.
python-template is distributed under the terms of the MIT license.