This is a modern Python project template designed with best practices for maintainable, scalable Python applications.
- Python: 3.12+ (managed by uv)
- Package Management: uv - extremely fast Python package manager
- Testing: pytest with coverage reporting
- Linting & Formatting: Ruff (replaces black, isort, flake8)
- Task Runner: Task (replaces Makefiles)
- Pre-commit: Automated code quality checks
- Configuration: Pydantic Settings with environment-based configs
- Containerization: Docker with uv support
- CI/CD: GitHub Actions with caching
src/
├── python_project_template/ # Main package directory
│ ├── __init__.py
│ └── configuration/ # Pydantic-based configuration management
│ ├── __init__.py
│ ├── config_settings.py # Environment-specific settings
└── test/ # Test suite
├── conftest.py # Pytest fixtures and configuration
└── test_*.py # Test files
- Use
uv syncto install dependencies and create virtual environment - Activate with
source .venv/bin/activateor useuv run <command> - All commands should be prefixed with
uv runwhen outside activated environment
- Import style: Use Ruff's isort-compatible import sorting
- Type hints: Required for all public functions and methods
- Type checking: Project uses multiple type checkers:
- ty for fast Rust-based type checking (configuration in
ty.toml) - pyrefly for advanced type analysis with granular error control (configuration in
pyrefly.toml)
- ty for fast Rust-based type checking (configuration in
- Docstrings: Use Google-style docstrings for classes and functions
- SOLID principles: Follow SOLID design principles for maintainable code
- Tests located in
src/test/directory - Use pytest markers for test categorization:
@pytest.mark.slowfor slow tests@pytest.mark.test_markfor testing purposes
- Test coverage target: 80%+
- Run tests with:
uv run pytest ./src/test
- Use Pydantic Settings for all configuration
- Environment-specific configs in
pyproject.tomlunder[config.<env>] - Required environment variable:
ENVIRONMENT(e.g., "local", "dev", "prod") - Configuration priority order:
- CLI arguments
- Environment-specific pyproject.toml table
- Default pyproject.toml table
- Environment variables
task linter: Run Ruff linter with auto-fixtask linter-watch: Run Ruff linter in watch modetask formatter: Run Ruff formattertask ty-checker: Run ty type checker (fast Rust-based)task pyrefly-checker: Run pyrefly type checker (advanced analysis)task run-test: Execute test suitetask precommit: Run pre-commit hookstask check_updatable_libs: Check for dependency updatestask dc-up: Start docker compose servicestask dc-exec: Execute command in running container
- Extend
SourceSettingsorBasicSettingsclasses - Use
Fieldwithaliasfor environment variable mapping - Include proper type annotations
- Add validation methods when necessary
- Use multi-stage builds when possible
- Install dependencies with
uv sync --frozen - Set
ENVIRONMENTvariable appropriately - Mount source code as volumes for development
- Add runtime dependencies with:
uv add package-name - Add dev dependencies with:
uv add --group dev package-name - Keep dependencies minimal and well-justified
- Pin major versions for stability
- Trailing whitespace removal
- End-of-file fixing
- YAML/TOML validation
- Ruff linting and formatting
- UV dependency validation
- Multi-OS testing (Ubuntu, macOS)
- Python 3.12
- Dependency caching
- Pre-commit hook validation
- Full test suite execution
- Test-driven development - Write tests for new functionality
- Small, focused commits - Use conventional commit messages
- Environment variables - Never hardcode configuration values
- Error handling - Use proper exception handling and logging
- Performance - Leverage uv's speed for dependency operations
- Security - Use
safetyfor vulnerability scanning
class BasicSettings(SourceSettings):
new_setting: str = Field(
alias="NEW_SETTING",
description="Description of the setting"
)import pytest
def test_new_functionality():
# Arrange
expected = "expected_value"
# Act
result = function_under_test()
# Assert
assert result == expected# Runtime dependency
uv add package-name
# Development dependency
uv add --group dev package-nameRemember: This template prioritizes developer experience, code quality, and maintainability. All suggestions should align with these principles.