Skip to content
/ python-project Public template

A template repository for a containerized Python application that manages its environments using Hatch and runs its integration test on Google Cloud Run.

License

Notifications You must be signed in to change notification settings

h-holm/python-project

Repository files navigation

Python Project Template

Python 3.13 License: MIT Hatch Ruff Mypy Pytest pre-commit Deploy to Cloud Run CodeQL pre-commit.ci status

A template repo that enables quickly setting up an end-to-end CI/CD pipeline that tests and deploys a containerized Python application. The placeholder Python logic computes a Fibonacci number.

Features ✅

  • Seamless environment management via Hatch
  • Lightning-fast dependency resolution via uv
  • Primary dependencies and tooling configuration in the PEP-recommended pyproject.toml file
  • (Sub-)dependency locking in requirements.txt files via hatch-pip-compile
  • Linting and formatting using ruff
  • Static type checking using mypy
  • pytest for unit tests with coverage-based reporting
  • ./src layout to separate application logic from tests and project metadata
  • Sane logging configured in a single logging.conf file
  • Optional quality-of-life add-ons:
    • pre-commit hooks installable via the hooks script of the lint Hatch environment
    • (further) enforcing of uniform formatting via an .editorconfig
    • recommended VS Code settings and extensions through a .vscode subdirectory
    • a Dev Container-based development environment

On any pull request, do the following while targeting a stg staging environment:

On merge (or push) into the main branch, additionally do the following while targeting a prd production environment:

  • deploy a Cloud Run job,
  • promote the container image by adding tags such as latest, main and the SemVer tag (if any).

Requirements

Ensure Hatch is installed on your system.

Development

Running the Code

Run the main.py entrypoint with the --help flag for an explanation to the application logic:

hatch run python src/python_project/main.py --help          # Uses the "default" Hatch environment.
hatch run default:python src/python_project/main.py --help  # Equivalent to not specifying "default:".

Unit Tests

Run the test script of the "test" Hatch environment to execute the pytest-backed unit tests and generate a coverage report:

hatch run test:test

Formatting, Linting and Type Checking

Run the lint script of the "lint" Hatch environment to perform (1) formatting and linting using ruff and (2) static type checking using mypy.

hatch run lint:lint

Set up pre-commit hooks that always align with the "lint" Hatch environment:

hatch run lint:hooks

Bumping the Version

Run hatch version followed by the SemVer component to bump, e.g.:

hatch version patch  # Or `hatch version minor` or `hatch version major`.

Commit the updated __version__.py script to version control before creating a git tag. Ensure the tag has the same name as the (now bumped) version:

git tag -a $(hatch version) -m 'Descriptive tag message'

License

See LICENSE.

About

A template repository for a containerized Python application that manages its environments using Hatch and runs its integration test on Google Cloud Run.

Resources

License

Stars

Watchers

Forks

Packages

No packages published