A modern, production-ready Python template for academic research projects with built-in support for reproducibility, documentation, testing, and publication workflows.
- Quick start
- Installation options
- Code quality tools
- Testing
- Documentation
- Quick file structure overview
- License
uv
# Install uv (if not already installed)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Clone the template
git clone https://github.com/Atomic-Samplers/template.git
cd template
# Create environment and install dependencies
uv sync
# Two ways to run commands with uv:
# 1. Using 'uv run' prefix
uv run pytest
uv run python scripts/my_script.py
...
# 2. Activate the environment shell
source .venv/bin/activate
pytest
python scripts/my_script.py
...conda
# Install miniforge if you don't have conda
curl -L -O "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
# Clone the template
git clone https://github.com/Atomic-Samplers/template.git
cd template
# Create environment
conda create -n template python=3.13
conda activate template
# Install package in editable mode
pip install -e ".[dev]"
# Run things normally
pytest
python scripts/my_script.py
...venv + pip
# Assuming a non-system Python installation is available
git clone https://github.com/Atomic-Samplers/template.git
cd template
# Create virtual environment
python -m venv .venv
source .venv/bin/activate
# Install package in editable mode
pip install -e ".[dev]"
# Run things normally
pytest
python scripts/my_script.py
...Three installation extras are available:
dev: Code quality tools (linters, formatters, type checkers)docs: Documentation tools (MkDocs and Material for MkDocs)tests: Testing tools (pytest and coverage)
When installing, include any combination of these extras.
# uv
uv sync --extra dev --extra docs --extra tests
# pip or conda
pip install -e ".[dev, docs, tests]"ruff (linting)
# Check code with Ruff
ruff check .
# Auto-fix issues
ruff check --fix .
# Allow unsafe fixes
ruff check --fix --unsafe-fixes .black (formatting)
# Format code with Black
black .
# Check without modifying
black --check .pyright (type checking)
# just run pyright
pyrightdocformatter (docstring formatting)
# format docstrings
docformatter -i -r .Pre-commit hooks are useful to automatically run code linters and formatters before each commit.
# install hooks
pre-commit install
# (optional) run manually on all files
pre-commit run --all-files
# after installation, hooks run automatically on git commit
git commit -m "Your commit message" # <- hooks run at this pointConfigured hooks:
ruff- Fast Python linter (checks code quality)black- Code formatter (Python files and Jupyter notebooks)docformatter- Docstring formatterblacken-docs- Format code in documentationtrailing-whitespace&end-of-file-fixer- Clean up files
# Run all tests
pytest
# Run with coverage
pytest --cov=template --cov-report=html
# Run specific test file
pytest tests/test_core.py
# Run with verbose output
pytest -v
# Run printing stdout during tests
pytest -s
# Run and stop after first failure
pytest -x
# Run only tests matching a keyword
pytest -k "keyword"Place tests in the tests/ directory, the folder structure does not really matter but it is recommended to mirror the structure of the src/template/ source code folder.
from template.examples.example import example_function
def test_example_function():
assert example_function().startswith("Hello from")Codecov allows you to track code coverage over time and identify untested parts of your codebase, you can see the coverage report here. To enable coverage reports with Codecov:
- Sign up at codecov.io
- Give codecov access to your GitHub repository (must be public for free plan) and configure it.
- Add the provided
CODECOV_TOKENfrom codecov to the repository secrets on GitHub:- Settings β Secrets and variables β Actions
- New repository secret:
CODECOV_TOKEN
The workflow in .github/workflows/tests.yml is already set up to upload coverage reports to Codecov when pushing to the repository. Coverage uploads automatically when configured.
Documentation is built with MkDocs and Material for MkDocs.
Follow the instruction to install the docs extra, then run:
# Serve docs locally with live reload, will open at http://localhost:8000
mkdocs serve
# Build static documentation site
mkdocs build- Documentation files live in
docs/, structured in Markdown. - Configuration in
mkdocs.yml
Using github actions, you can automatically deploy documentation to GitHub Pages on each push to main. Documentation automatically deploys to GitHub Pages on push to main. View at:
https://USERNAME.github.io/REPO
To enable, go to your GitHub repository:
- Go to Settings β Pages
- Source: Deploy from a branch
- Branch:
gh-pageskeep the folder toroot/ - Save
src/- Main package source codetests/- Unit and integration testsdocs/- Documentation source files.venv/- Virtual environment (if using venv).github/workflows/- GitHub Actions workflows for CI/CD, testing, and deployment.pre-commit-config.yaml- Pre-commit hooks configurationmkdocs.yml- MkDocs configuration filepyproject.toml- Project metadata and dependenciessrc/template/py.typed- Marker file indicating package is typed.python-version- Specifies Python version for pyenv and similar toolsREADME.md- Project overview and instructionsCHANGELOG.md- Record of changes and versionsCODE_OF_CONDUCT.md- Community code of conductMANIFEST.in- Specifies additional files to include in the packageLICENSE.md- License information.gitignore- Specifies files and directories to ignore in Git
This project is licensed under the terms of the BSD 3-Clause license.
This template was heavily inspired by Quacc's project template: https://github.com/Quacc/Quacc