A comprehensive, production-ready Python project template that incorporates modern development practices, tools, and workflows. This template provides everything you need to start developing, testing, and deploying Python packages with confidence.
- devenv.sh - Reproducible development environments using Nix
- Cross-platform support - Works on macOS and Linux with conditional package loading
- direnv integration for automatic environment activation
- Python 3.12 with modern tooling
- uv - Ultra-fast Python package installer and resolver
- hatchling - Modern build backend
- Dynamic versioning from Git tags using
uv-dynamic-versioning - Dependency groups for clean separation of dev/prod dependencies
- pytest with async support and comprehensive plugins:
- Coverage reporting with HTML output
- Snapshot testing with syrupy
- Watch mode with pytest-watcher
- ruff - Lightning-fast linting and formatting
- Pre-commit hooks with comprehensive checks:
- Code formatting (ruff-format)
- Import sorting
- TOML validation
- Markdown formatting
- Security scanning (trufflehog)
- Shell script checking
- Typo detection
- GitHub Actions workflow with:
- Multi-OS testing (Ubuntu + macOS)
- Automatic PyPI publishing on tags
- Trusted publishing (no API keys needed)
- Artifact storage
- Renovate for automated dependency updates
- Semantic versioning with automatic tag-based releases
- Markdown linting with customizable rules
- License (MIT) included
- Comprehensive .gitignore for Python projects
- VS Code configuration for optimal development experience
-
Clone and setup:
git clone <your-repo-url> cd modern-python-project direnv allow # If using direnv # OR nix develop # If not using direnv
-
Install dependencies:
# Dependencies are automatically installed via devenv # But you can manually sync if needed: uv sync --all-extras
-
Run tests:
test-all
-
Start developing:
# Watch mode for tests test-watch # Format code format # Build package build
The development environment provides these commands:
build- Build the Python packageformat- Run all formatters and linterstest-all- Run the complete test suitetest-snapshot-update- Update test snapshotstest-watch- Run tests in watch modedeps-upgrade- Upgrade all dependencies
modern-python-project/
βββ modern_python_project/ # Main package code
β βββ __init__.py
β βββ main.py # CLI entry point
β βββ my_function.py # Example module
βββ modern_python_project_tests/ # Test package
β βββ __snapshots__/ # Snapshot test files
β βββ test_cli.py # CLI tests
β βββ test_my_function.py # Module tests
βββ devenv.nix # Development environment config
βββ devenv.yaml # devenv input configuration
βββ pyproject.toml # Project metadata and tool config
βββ uv.lock # Locked dependencies
βββ README.md # This fileDependencies are managed in pyproject.toml:
- Main dependencies: Listed under
dependencies - Development dependencies: Listed under
dependency-groups.dev
- Coverage: Configured to maintain 80% minimum coverage
- Pytest: Async support enabled, comprehensive reporting
- Snapshots: Automatic snapshot testing for CLI and functions
- Ruff: Fast linting and formatting with import sorting
- Pre-commit: Comprehensive hooks for code quality
- Coverage: HTML reports generated in
coverage_html/
- Make changes to your code
- Run tests with
test-watchfor immediate feedback - Format code with
formatbefore committing - Commit changes - pre-commit hooks will run automatically
- Push to GitHub - CI will run tests on multiple platforms
- Create release by pushing a tag (format:
vX.X.X)
Publishing to PyPI is fully automated:
- Create a new tag:
git tag v1.0.0 - Push the tag:
git push origin v1.0.0 - GitHub Actions will automatically build and publish to PyPI
The project uses trusted publishing, so no API keys are required.
This template embodies modern Python development best practices:
- Fast feedback loops with watch mode testing
- Consistent code quality with automated formatting and linting
- Reliable builds with locked dependencies and reproducible environments
- Secure publishing with trusted publishing and no stored secrets
- Cross-platform support with conditional package loading
- Comprehensive testing with coverage tracking and snapshot testing
- Automated maintenance with dependency updates and security scanning
Perfect for both solo projects and team development, this template scales from simple scripts to complex packages while maintaining development velocity and code quality.
MIT License - see LICENSE file for details.
- Fork the repository
- Create a feature branch
- Make your changes
- Run the test suite
- Submit a pull request
The pre-commit hooks and CI will ensure code quality and test coverage.