Opinionated Python project template.
- uv — Fast package manager
- ruff — Linting & formatting with Google-style docstrings enforced
- pyright — Strict type checking
- import-linter — Layered architecture enforcement
- pytest — Testing with coverage support
- pre-commit — Git hooks for all checks (local execution via uv)
To use this template you only need the python-functions.sh script. The script uses copier to fetch the template directly from GitHub when you create a project. If needed, you could modify the template and point the script to either a local path or your own repository.
Download the script and add the following to your .zshrc (or .bashrc):
# --- Python Project Management ---
# Where new projects will be created
export DEV_DIR="$HOME/developer"
# Download python-functions.sh to a location of your choice, then source it:
source "$HOME/.config/python-functions.sh"
# Optional: Use your own fork or a local template path
# export PYTHON_TEMPLATE_REPO="/path/to/local/template"
# export PYTHON_TEMPLATE_REPO="gh:your-username/python-template"Requirements: uv and git must be installed.
Once configured, you have access to the following commands:
mkpyproject <name>: Create a new project using this template.- Automatically fills author details from your git config.
- Initializes git, installs dependencies, and sets up pre-commit hooks.
workon [name]: Switch to an existing project.- If no name is provided, lists available projects.
- Checks for and can activate the
.venv.
rmproject <name>: Safely remove a project directory.lspy: List all python projects in yourDEV_DIR.cleanup_venvs [--dry-run]: Batch remove.venvfolders to save space.
Create a new project:
mkpyproject my-new-serviceThis single command will:
- Generate the project structure from this template.
- Initialize a new git repository (branch
main). - Install dependencies (creating a
.venv). - Setup pre-commit hooks for code quality.
- Format the code and create the initial commit.
- Navigate you into the project directory so you can start coding immediately.
- Activate the virtual environment.
Why auto-activate? Even though
uv runhandles environments automatically, we activate the.venvas a safety measure. This prevents accidentally runningpip installagainst your system Python and shows the correct Python version in your prompt.
Switch to a project:
workon my-new-service
# cd's to ~/developer/my-new-serviceworkon
# lists projects in ~/developer/If you prefer not to use the helper script, you can run copier directly. You will be prompted for values:
uvx copier copy gh:jwa91/python-template path/to/destination| File | Purpose |
|---|---|
pyproject.toml |
Project config, dependencies, uv settings |
ruff.toml |
Linting rules with docstring enforcement |
pyrightconfig.json |
Strict type checking config |
.importlinter |
Import layering rules (main -> utils) |
.pre-commit-config.yaml |
Git hooks for ruff, pyright, import-linter |
AGENTS.md |
AI assistant instructions and architecture |
py.typed |
PEP 561 marker for typed package |
Enforces a strict layered architecture:
┌─────────────────────────────┐
│ my_project.main │ ← Top layer (entry point)
└─────────────┬───────────────┘
│ can import from ↓
┌─────────────▼───────────────┐
│ my_project.utils │ ← Bottom layer (foundational)
└─────────────────────────────┘
# Run tests
uv run pytest
# Lint and format
uv run ruff check .
uv run ruff format .
# Type check
uv run pyright
# Check import layering
uv run lint-imports