A minimal Python project template following modern best practices and industry standards.
Author: JacobPEvans Created: July 12, 2025 License: Apache License 2.0 Python Version: 3.11+
- Python 3.11 or higher
- Git
-
Clone this repository
git clone <repository-url> cd python-template
-
Create and activate a virtual environment
# Windows python -m venv .venv .\.venv\Scripts\Activate.ps1 # Linux/macOS python3 -m venv .venv source .venv/bin/activate
Note: We use
.venvas the directory name to match common conventions and ensure it's ignored by git. -
Install dependencies
# Development installation (includes dev dependencies) pip install -e ".[dev]" # Or just production dependencies pip install -e .
Note: The
-eflag installs in "editable" mode, so changes to your code take effect immediately. -
Set up pre-commit hooks (Required for contributing)
# Pre-commit is already installed with dev dependencies # Install the git hook scripts pre-commit install # (Optional) Run on all files to test setup pre-commit run --all-files
Note: Pre-commit hooks will run automatically on every commit and may auto-fix formatting issues.
# Run all tests
pytest
# Run tests with coverage
pytest --cov=src/hello_world --cov-report=html
# Run tests with coverage (same as GitHub Actions/CodeCov) - REQUIRES 100% coverage
pytest --cov --cov-branch --cov-report=xml --cov-fail-under=100
# Run tests in verbose mode
pytest -v
# Run specific test file
pytest tests/test_main.py -vThis project enforces 100% code coverage. All pull requests must maintain 100% coverage or they will be automatically rejected by GitHub Actions.
Use pytest --cov --cov-branch --cov-report=xml --cov-fail-under=100 to ensure your changes meet this requirement before committing.
This project uses multiple workflows for maintaining code quality:
tests.yml: Runs pytest with coverage across Python 3.11-3.13ci.yml: Enforces code quality with auto-fixing and validation
Pre-commit hooks automatically run code formatting, linting, and type checking before each commit to ensure code quality.
# Pre-commit is already installed with dev dependencies
# Install the git hook scripts
pre-commit install
# Test the setup
pre-commit run --all-filesNote: Once installed, pre-commit will automatically run on every
git commit. If any checks fail, the commit will be blocked until issues are fixed. Code formatting tools like Black and isort will auto-fix many issues.
- β
Modern Python packaging with
pyproject.toml - β Automated testing with pytest and coverage
- β Dual GitHub Actions workflows (testing + code quality)
- β Pre-commit hooks for code quality enforcement
- β Type hints and mypy type checking
- β Code formatting with Black and isort
- β Linting with flake8
- β
Pre-configured
.gitignore
python-template/
βββ .github/
β βββ workflows/
β βββ tests.yml # GitHub Actions - Testing
β βββ ci.yml # GitHub Actions - Code Quality
βββ src/
β βββ hello_world/
β βββ __init__.py # Package initialization
β βββ main.py # Main application code
βββ tests/
β βββ __init__.py # Test package initialization
β βββ test_main.py # Unit tests
βββ .gitignore # Git ignore rules
βββ .pre-commit-config.yaml # Pre-commit hooks configuration
βββ README.md # Project documentation
βββ pyproject.toml # Modern Python packaging & tool config
βββ pytest.ini # Pytest configuration
βββ requirements-dev.txt # Development dependencies
If you prefer the minimal approach:
-
Clone the repository:
git clone <repository-url> cd python-template
-
Create a virtual environment:
python3 -m venv .venv source .venv/bin/activate # On Windows: .\.venv\Scripts\activate
-
Install dependencies:
pip install -e ".[dev]"
Run the hello world application:
python -m hello_world.mainOr import and use in your code:
from hello_world import greet
print(greet("Python")) # Output: Hello, Python!pytest tests/ -v# Generate HTML coverage report
pytest tests/ -v --cov=src/hello_world --cov-report=html
# Generate XML coverage report (used by CodeCov in CI)
pytest --cov --cov-branch --cov-report=xml --cov-fail-under=100pip install -e .- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Run tests with coverage before committing (see coverage requirements above)
- Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request