A production-ready Python project template featuring modern tooling, automated code quality checks, and industry best practices.
Quick Start β’ Features β’ Architecture β’ Documentation
| Metric | Impact |
|---|---|
| 10x Faster Linting | Ruff replaces Black, isort, Flake8 in a single tool |
| 100% Type Coverage | Full mypy strict mode integration |
| Zero Config Setup | One command to scaffold and start coding |
| CI/CD Ready | Pre-configured GitHub Actions workflows |
| Security First | Bandit security scanning built-in |
flowchart LR
subgraph DEV["Development Phase"]
A[Write Code] -->|save| B[Save File]
end
subgraph VCS["Version Control"]
B -->|stage| C[Stage Changes]
C -->|commit| D[Commit]
D -->|push| E[Push to Remote]
end
subgraph GATES["Quality Gates"]
direction TB
G1[Ruff - Lint & Format]
G2[Mypy - Type Check]
G3[Bandit - Security Scan]
G4[Commitizen - Commit Validation]
end
D -.->|triggers| G1
D -.->|triggers| G2
D -.->|triggers| G3
D -.->|triggers| G4
graph LR
subgraph Project["π project_name"]
direction LR
subgraph Source["src/project_name/"]
A["__init__.py<br/><i>Package init</i>"]
B["main.py<br/><i>Core logic</i>"]
C["my_cli.py<br/><i>CLI interface</i>"]
D["rich_demo.py<br/><i>Terminal UI</i>"]
end
subgraph Tests["tests/"]
E["test_main.py<br/><i>Test suite</i>"]
end
subgraph Config["Configuration"]
F["pyproject.toml<br/><i>Project config</i>"]
G[".pre-commit-config.yaml<br/><i>Git hooks</i>"]
H[".gitignore"]
I["README.md"]
end
end
|
|
- Python 3.11+
- Cookiecutter (
pip install cookiecutter)
# Generate from template
cookiecutter gh:asq-sheriff/cookiecutter-modern-python
# Navigate to your new project
cd your-project-name
# Create and activate virtual environment
python3 -m venv .venv
source .venv/bin/activate # macOS/Linux
# .venv\Scripts\activate # Windows
# Install development dependencies
pip install -e ".[dev]"
# Initialize git and pre-commit hooks
git init
pre-commit install --install-hooksflowchart LR
CODE[Your Python Code]
CODE --> RUFF
CODE --> MYPY
CODE --> PYTEST
CODE --> BANDIT
subgraph Linting["π Linting & Formatting"]
RUFF["<b>Ruff</b><br/>Replaces Black + isort + Flake8<br/>10-100x faster"]
end
subgraph Typing["π· Type Checking"]
MYPY["<b>Mypy</b><br/>Strict mode<br/>Full type inference"]
end
subgraph Testing["π§ͺ Testing"]
PYTEST["<b>Pytest</b><br/>Async support<br/>Coverage reports"]
end
subgraph Security["π Security"]
BANDIT["<b>Bandit</b><br/>SAST scanning<br/>OWASP compliance"]
end
[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "{{ cookiecutter.project_slug }}"
version = "0.1.0"
description = "{{ cookiecutter.description }}"
authors = [{ name = "{{ cookiecutter.author_name }}", email = "{{ cookiecutter.author_email }}" }]
readme = "README.md"
requires-python = ">= {{ cookiecutter.python_version }}"
[project.optional-dependencies]
dev = [
"pre-commit>=4.4.0",
"ruff>=0.11.9",
"mypy>=1.15.0",
"bandit>=1.8.3",
"docformatter>=1.7.7",
"commitizen>=4.7.0",
"pytest>=8.0.0",
"pytest-cov>=4.1.0",
"pytest-asyncio>=0.23.0",
]flowchart TD
A[git add .] -->|stage changes| B[git commit]
B -->|triggers| HOOKS
subgraph HOOKS["Pre-commit Hooks"]
direction TB
H1[ruff check --fix]
H2[ruff format]
H3[mypy]
H4[bandit]
H5[commitizen]
H1 -->|auto-fix lint| H2
H2 -->|format code| H3
H3 -->|type check| H4
H4 -->|security scan| H5
H5 -->|validate message| DONE[Hooks Complete]
end
HOOKS --> CHECK{All Checks Pass?}
CHECK -->|yes| SUCCESS[Commit Succeeds]
CHECK -->|no| FAIL[Commit Blocked]
FAIL -->|fix issues| A
SUCCESS -->|optional| PUSH[git push]
| Command | Description |
|---|---|
ruff check . |
Run linter on all files |
ruff check --fix . |
Auto-fix linting issues |
ruff format . |
Format all Python files |
mypy . |
Run type checking |
pytest --cov=src |
Run tests with coverage |
bandit -r src/ |
Security vulnerability scan |
pre-commit run --all-files |
Run all hooks manually |
As of May 2025, Typer has a known incompatibility with Click 8.2.0+. Workaround:
pip install "click==8.1.8"Track updates: Typer GitHub Issue #1215
{{ cookiecutter.project_slug }}/
βββ src/
β βββ {{ cookiecutter.project_slug }}/
β βββ __init__.py
β βββ main.py # Core functionality
β βββ my_cli.py # CLI with Typer
β βββ rich_demo.py # Rich terminal demos
βββ tests/
β βββ test_main.py
βββ .pre-commit-config.yaml
βββ pyproject.toml
βββ .gitignore
βββ README.md
- Fork the repository
- Create a feature branch (
git checkout -b feat/amazing-feature) - Commit changes (
git commit -m 'feat: add amazing feature') - Push to branch (
git push origin feat/amazing-feature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.
If you use this template, please acknowledge the creator:
Created by Aejaz (https://github.com/asq-sheriff)
Template: cookiecutter-modern-python
Or include a badge in your README:
[](https://github.com/asq-sheriff/cookiecutter-modern-python)Aejaz
- GitHub: @asq-sheriff
Built with modern Python best practices
Python β’ Ruff β’ Mypy β’ Pytest β’ Pre-commit β’ GitHub Actions
Keywords: Python template, Cookiecutter, Python best practices, Ruff linter, Mypy type checking, pre-commit hooks, Python project structure, modern Python development, Python CI/CD, Python testing, pytest, Python security, bandit, Python automation, Python tooling