This folder contains a complete, production-ready cookiecutter template for starting new Python projects.
- Production-ready cookiecutter template with 50+ configuration options
- Complete project structure with modern Python best practices
- CI/CD workflows for GitHub Actions with multi-version testing
- Security scanning and compliance tools (OWASP Top 10 compliant)
- Docker containerization with production-ready configurations
- Performance testing with Locust and k6
- Background job processing with ARQ or Celery
- Redis caching and health check endpoints
- Sentry monitoring integration
cookiecutter-python-template/
├── cookiecutter.json # Main configuration (40+ options)
├── hooks/
│ ├── pre_gen_project.py # Pre-generation validation
│ └── post_gen_project.py # Post-generation cleanup
├── {{cookiecutter.project_slug}}/ # Main template (60+ files)
│ ├── .github/
│ │ └── workflows/ # 8 CI/CD workflows (CI, codecov, release, security, docs, etc.)
│ ├── src/{{cookiecutter.project_slug}}/
│ │ ├── __init__.py
│ │ ├── cli.py # Optional CLI
│ │ ├── api/ # API endpoints (optional)
│ │ │ └── health.py # Health check endpoints
│ │ ├── core/ # Core functionality
│ │ │ ├── cache.py # Redis caching (optional)
│ │ │ └── sentry.py # Sentry monitoring (optional)
│ │ ├── jobs/ # Background jobs (optional)
│ │ │ └── worker.py # ARQ/Celery workers
│ │ ├── middleware/ # API middleware (optional)
│ │ │ └── security.py # OWASP security middleware
│ │ └── utils/ # Utility modules
│ ├── tests/
│ │ ├── conftest.py
│ │ ├── unit/ # Unit tests
│ │ ├── integration/ # Integration tests
│ │ ├── load/ # Load tests (optional)
│ │ │ ├── locustfile.py # Locust configuration
│ │ │ ├── k6-script.js # k6 configuration
│ │ │ └── README.md # Load testing guide
│ │ └── test_example.py
│ ├── docs/
│ │ ├── ADRs/ # Architecture Decision Records
│ │ ├── planning/ # Project planning templates
│ │ └── PYTHON_COMPATIBILITY.md # Python version compatibility guide
│ ├── pyproject.toml # UV/PEP 621 configuration
│ ├── Dockerfile # Production-ready container (optional)
│ ├── docker-compose.yml # Development environment (optional)
│ ├── docker-compose.prod.yml # Production environment (optional)
│ ├── .dockerignore # Docker ignore patterns
│ ├── .pre-commit-config.yaml # Pre-commit hooks
│ ├── codecov.yml # Code coverage config
│ ├── renovate.json # Dependency updates
│ ├── mkdocs.yml # Documentation site
│ ├── README.md
│ ├── LICENSE
│ ├── SECURITY.md
│ ├── CONTRIBUTING.md
│ └── ... (40+ more files)
├── {{ cookiecutter.repo_name }}/ # Optional monitoring utilities
│ ├── src/monitoring/ # Monitoring components
│ │ ├── ab_testing_dashboard.py
│ │ ├── metrics_collector.py
│ │ ├── performance_dashboard.py
│ │ └── service_token_monitor.py
│ └── tests/unit/monitoring/ # Monitoring tests
├── .github/
│ ├── workflows/
│ │ ├── validate-template.yml # Template validation
│ │ └── release-drafter.yml # Auto release notes
│ └── release-drafter.yml # Release config
├── .pre-commit-config.yaml # Template repo hooks
└── QUICK_START.sh # Interactive setup script
-
Create a new repository on GitHub:
- Repository name:
cookiecutter-python-template-2(or your choice) - Description: "Production-ready Python cookiecutter template"
- Public repository
- DO NOT initialize with README
- Repository name:
-
Copy this folder to the new repository:
# From your local machine cd /path/to/this/folder/cookiecutter-template git init git add . git commit -m "Initial commit: Production-ready Python cookiecutter template" git branch -M main git remote add origin https://github.com/YOUR_USERNAME/YOUR_REPO_NAME.git git push -u origin main
-
Enable as template repository:
- Go to repository Settings → General
- Check ✅ "Template repository"
# Install cookiecutter
pip install cookiecutter
# Use the template directly from this folder
cookiecutter /path/to/this/folder/cookiecutter-template
# Or after copying to your templates directory
cp -r cookiecutter-template ~/my-templates/
cookiecutter ~/my-templates/cookiecutter-templateMonitoring and Observability:
include_sentry: Sentry error tracking and APMinclude_health_checks: Kubernetes-ready health endpoints (liveness, readiness, startup)
Containerization:
include_docker: Multi-stage Dockerfile with security hardening- Docker Compose for development and production
- Non-root user, health checks, optimized caching
Performance and Scalability:
include_background_jobs: ARQ (async) or Celery task queuesinclude_caching: Redis caching with decorator patternsinclude_load_testing: Locust and k6 load testing tools
Security:
- API security middleware (OWASP headers, rate limiting, SSRF prevention)
- SBOM generation in release workflow (CycloneDX format)
- 7+ security scanning tools integrated
MCP Server Support (from zen-mcp-server):
include_mcp_server: Add MCP protocol supportmcp_transport: stdio/http/sse options
API Integration (from xero-practice-management):
include_api_client: API client factory patternapi_auth_type: OAuth2/API key/JWT authenticationinclude_retry_logic: Exponential backoff retryinclude_rate_limiting: Rate limiting support
Database/Ledger Patterns (from ledgerbase):
include_database: SQLAlchemy with migrationsinclude_repository_pattern: Repository patterninclude_unit_of_work: Unit of Work patterndatabase_dialect: PostgreSQL/MySQL/SQLite
Enhanced Security (from pp-security-master):
include_gitleaks: Secrets detectioninclude_compliance_docs: Compliance templatesinclude_threat_model: Threat modelinginclude_fuzzing: Fuzzing infrastructure
Financial Patterns (from FISProject):
include_financial_validators: Financial validationinclude_audit_logging: Audit trailuse_decimal_precision: Decimal for money
Complete project structure with:
Core Infrastructure:
- ✅ 8 GitHub Actions workflows (CI, codecov, security, docs, release, PyPI, fuzzing)
- ✅ UV + PEP 621 packaging (10-100x faster than pip/poetry)
- ✅ Hatchling build backend
- ✅ Cruft template update tracking
- ✅ Python 3.10-3.14 support with multi-version CI testing
Code Quality:
- ✅ Ruff consolidated linting
- ✅ BasedPyright strict type checking
- ✅ pytest with 80% coverage target
- ✅ SonarCloud continuous code quality and security analysis (optional)
- ✅ Pre-commit hooks (9+ automated checks)
- ✅ Mutation testing with mutmut
Documentation:
- ✅ MkDocs Material documentation site
- ✅ Python compatibility guide (version-specific features)
- ✅ Architecture Decision Records (ADRs)
Security (OWASP Top 10 Compliant):
- ✅ 7+ security tools (Bandit, Safety, OSV-Scanner, CodeQL, Gitleaks, etc.)
- ✅ SBOM generation (CycloneDX format)
- ✅ API security middleware (headers, rate limiting, SSRF prevention)
- ✅ Secrets scanning with Gitleaks
Production Features (Optional):
- ✅ Docker containerization (multi-stage, security-hardened)
- ✅ Kubernetes health checks (liveness, readiness, startup)
- ✅ Sentry monitoring (error tracking, APM, profiling)
- ✅ Background jobs (ARQ or Celery)
- ✅ Redis caching (decorator-based)
- ✅ Load testing (Locust and k6)
Optional Frameworks:
- ✅ Click CLI (optional)
- ✅ FastAPI with security middleware (optional)
- ✅ PyTorch ML (optional)
- ✅ SQLAlchemy with migrations (optional)
Expected User Impact:
- 100% of users: Enhanced security
- 40-50% of users: API integration patterns
- 40-50% of users: Database/ORM patterns
- 10-15% of users: Financial/ledger patterns
- 5-10% of users: MCP server patterns
Time Savings: 4-8 hours per project (120-240× ROI)
# Install cookiecutter and cruft
pip install cookiecutter cruft
# Option 1: Use with Cruft (recommended - enables template updates)
cruft create /path/to/cookiecutter-template
# Option 2: Use with Cookiecutter (traditional method)
cookiecutter /path/to/cookiecutter-template
# Answer prompts:
project_name [My Python Project]: My Awesome Project
python_version [3.12]: 3.12
license [MIT]: MIT
include_cli [yes]: yes
include_api_client [no]: yes
api_auth_type [oauth2]: oauth2
include_database [sqlalchemy_migrations]: sqlalchemy_migrations
include_repository_pattern [yes]: yes
# Generated project structure:
my_awesome_project/
├── .github/workflows/ # 4 CI/CD workflows
├── src/my_awesome_project/
│ ├── cli.py
│ ├── core/
│ └── utils/
├── tests/
├── docs/
├── pyproject.toml
├── uv.lock # UV lock file
├── .cruft.json # Template tracking (cruft only)
└── README.mdBoth this template repository and generated projects support SonarCloud for continuous code quality and security analysis.
The template repository itself is configured with SonarCloud to analyze hooks and template files:
- Project Already Created:
ByronWilliamsCPA_cookiecutter-python-template - Token Configured:
SONAR_TOKENsecret added to GitHub organization - Workflow Enabled:
.github/workflows/sonarcloud.ymlruns on push/PR - Dashboard: View SonarCloud Dashboard
When creating a new project with include_sonarcloud=yes, you need to:
-
Create SonarCloud Project:
- Go to SonarCloud
- Click "+" → "Analyze new project"
- Select your GitHub repository
- Choose your organization (e.g.,
williaby) - Project key will be:
{github_org}_{project_slug}
-
Configure GitHub Secret:
- If using organization-level token (recommended):
- Already configured as
SONAR_TOKENin organization secrets - No additional action needed
- Already configured as
- If using repository-level token:
- Go to repository Settings → Secrets and variables → Actions
- Add secret:
SONAR_TOKENwith your SonarCloud token
- If using organization-level token (recommended):
-
Verify Configuration:
# After project generation cd your-project # Check workflow exists ls .github/workflows/sonarcloud.yml # Check configuration cat sonar-project.properties
-
First Analysis:
- Push code to GitHub (main branch or PR)
- SonarCloud workflow runs automatically
- View results in SonarCloud Dashboard
Generated projects include:
- Quality Gate Enforcement: Fails if code doesn't meet quality standards
- PR Decoration: Shows issues directly in pull requests
- Coverage Tracking: Integrates pytest coverage reports
- Security Analysis: Detects vulnerabilities and security hotspots
- Code Smells: Identifies maintainability issues
- Technical Debt: Quantifies effort to fix issues
Both template and generated projects use CI-Based Analysis (not Automatic):
- ✅ Full Python language support
- ✅ Test coverage integration
- ✅ Quality gate enforcement
- ✅ Branch analysis and PR decoration
- ✅ Comprehensive metrics (security, maintainability, reliability)
This template includes enhanced support for Claude Code with user-level settings integration.
During project generation, you'll be prompted to set up user-level Claude Code settings. These settings enhance Claude Code's capabilities across all your projects:
What's Included:
- Global CLAUDE.md: Best practices, workflows, and development patterns
- Skills: Reusable capabilities for common tasks
- Agents: Specialized task handlers for security, testing, documentation, etc.
- Custom Commands: Slash commands and hooks for enhanced workflows
Setup Process:
When you create a new project using this template, the post-generation hook will:
- Check for existing user-level settings at
~/.claude/or~/.config/claude/ - Prompt you to set up settings if not found
- Clone the settings repo (default:
https://github.com/williaby/.claude) - Verify installation of CLAUDE.md, skills, agents, and commands
Manual Setup:
If you skip the automatic setup, you can install user-level settings later:
# Using the default settings repo
git clone https://github.com/williaby/.claude ~/.claude
# Or using your own settings repo
git clone https://github.com/YOUR_USERNAME/YOUR_CLAUDE_SETTINGS ~/.claudeBenefits:
✅ Consistent workflows across all projects ✅ Supervisor patterns with agent delegation ✅ Reusable skills for common tasks ✅ Custom slash commands for your workflow ✅ Global best practices inherited by all projects
Note: User-level settings are optional but recommended for the best Claude Code experience. Projects work without them but have enhanced capabilities when available.
This template fully supports Cruft for keeping generated projects in sync with template updates.
✅ Status: Cruft integration is working and tested
- Projects created with
cruft createinclude.cruft.jsontracking file cruft checkverifies template is up to datecruft updateapplies template changes to existing projectscruft diffshows pending template changes
- Stay Updated: Automatically pull in template improvements, bug fixes, and new features
- Selective Updates: Review and accept/reject changes before applying them
- Track Template Version:
.cruft.jsontracks which template version your project uses - Conflict Resolution: Smart merging handles conflicts between template updates and your changes
Create a new project with Cruft:
# Install cruft
pip install cruft
# Create project (automatically adds .cruft.json)
cruft create https://github.com/YOUR_USERNAME/YOUR_TEMPLATE_REPO
# Or use local path
cruft create /path/to/cookiecutter-python-templateCheck for template updates:
cd your-project
cruft checkUpdate your project:
cruft update
# Review changes, accept/reject updatesView differences:
cruft diffUpdate template variables:
cruft update --variablesYou can add a GitHub Action to automatically check for template updates:
# .github/workflows/cruft-update.yml
name: Check Template Updates
on:
schedule:
- cron: '0 0 * * 1' # Weekly on Monday
workflow_dispatch:
jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check for template updates
run: |
pip install cruft
cruft check- v2.1 (2025-11-18): Production-Ready Enhancement Release
- NEW: Python 3.10-3.14 cross-version support with multi-version CI testing
- NEW: Docker containerization (multi-stage, security-hardened, optional)
- NEW: Kubernetes health check endpoints (liveness, readiness, startup)
- NEW: Sentry monitoring integration (error tracking, APM, profiling)
- NEW: Background job processing (ARQ and Celery options)
- NEW: Redis caching with decorator patterns
- NEW: Load testing tools (Locust and k6)
- NEW: API security middleware (OWASP headers, rate limiting, SSRF prevention)
- NEW: SBOM generation in release workflow (CycloneDX format)
- NEW: Codecov multi-version coverage tracking
- IMPROVED: Post-generation hook removes unwanted optional files
- IMPROVED: Success message shows included features and setup steps
- OWASP Top 10 compliant security configuration
- 50+ configuration options (up from 40+)
- 60+ template files (up from 46)
- v2.0 (2025-11-17): UV & Cruft Migration Release
- BREAKING: Migrated from Poetry to UV for package management
- Added Cruft support for template updates
- Updated all dependencies to use standard PEP 621 format
- Changed build backend from poetry-core to hatchling
- Updated all documentation and CI/CD workflows for UV
- Added
.cruft.jsonfor template tracking - 10-100x faster dependency resolution with UV
- v1.2 (2025-11-17): Claude Code Enhancement Release
- Added interactive user-level Claude settings setup
- Streamlined dependency management (Poetry as single source of truth)
- Simplified CLI help text for better UX
- Enhanced post-generation hook with Claude Code integration
- v1.1 (2025-11-17): Streamlined release
- Removed reference documentation (docs-reference/)
- Added optional monitoring utilities
- Focused on core template functionality
- v1.0 (2025-11-17): Initial release with patterns from 5 repositories
- 73 files, 40+ configuration options
- Complete Python project template
- QUICK_START.sh: Interactive script for template setup
- cookiecutter.json: All configuration options with detailed comments
- Template README: Each generated project includes comprehensive documentation
This template was created from patterns found in:
- image-preprocessing-detector: Base project structure
- zen-mcp-server: MCP protocol patterns
- xero-practice-management: API integration patterns
- pp-security-master: Security enhancements
- FISProject: Financial system patterns
- ledgerbase: Database/ledger patterns
For questions or issues:
- Review the generated project's documentation (in each project's
docs/folder) - Check the cookiecutter.json file for all available configuration options
- Use QUICK_START.sh for interactive template setup
Optional monitoring components available for advanced use cases:
- A/B Testing Dashboard: Track and visualize A/B test results
- Metrics Collector: Collect and aggregate system metrics
- Performance Dashboard: Monitor application performance
- Service Token Monitor: Track service token usage and rotation
These components are not included in generated projects by default but can be copied manually for specific use cases.
Configuration Options: 50+ options Template Files: 60+ files in main template Python Versions: 3.10-3.14 (full multi-version CI support) GitHub Workflows: 8 automated workflows Security Tools: 7+ integrated scanners (OWASP compliant) Production Features: Docker, Sentry, health checks, caching, background jobs, load testing Coverage: Production-ready for 95%+ of Python project needs Last Updated: 2025-11-18