This repository is a modular Python template for building component-based projects using modern development practices. It supports independent components with their own dependencies, unit and integration tests, full CI/CD setup, and type/lint/test enforcement using uv, mypy, ruff, pytest, and coverage.
This template uses uv for dependency and environment management. No pip, venv, or requirements.txt are needed.
curl -LsSf https://astral.sh/uv/install.sh | shgit clone https://github.com/nimitmk7/pytemplate.git
cd pytemplateuv venv .venv
source .venv/bin/activateuv syncuvx ruff check .uvx mypy . --python-executable=$(which python)coverage run -m pytest tests src/*/tests
coverage report -mcoverage html -d coverage-html
open coverage-html/index.htmlcoverage run -m pytest src/logger/tests/test_logger.pyEach component lives in its own directory under src/, with colocated unit tests and an individual pyproject.toml.
src/
├── calculator/
│ ├── calculator.py
│ ├── calculator_interface.py
│ ├── pyproject.toml
│ └── tests/
├── logger/
│ ├── logger.py
│ ├── logger_interface.py
│ ├── pyproject.toml
│ └── tests/
├── notifier/
│ ├── notifier.py
│ ├── notifier_interface.py
│ ├── pyproject.toml
│ └── tests/
tests/
├── integration/
│ ├── test_calc_logger.py
│ └── test_logger_notifier.py
├── e2e/
│ └── test_e2e_full_flow.py
Each component has its own tests/ folder under src/<component>/tests/, testing that component in isolation.
Found in tests/integration/, these test interactions between two components:
test_calc_logger.py— tests logging of calculator resultstest_logger_notifier.py— tests triggering notification based on logged outputs
Found in tests/e2e/, simulating a full pipeline:
test_e2e_full_flow.py— simulates calculator → logger → notifier workflow
The pipeline (.circleci/config.yml) ensures:
- Linting with
ruff - Type checking with
mypy - Test running with
pytestandcoverage - Test results and coverage reports are stored as artifacts
test-results/junit.xml— test results in JUnit formatcoverage-html/index.html— code coverage visual report
Artifacts can be accessed from the Artifacts tab in any CircleCI job page.
To generate and upload an HTML coverage report in CircleCI, the config includes:
- run:
name: Run Tests
command: |
coverage run -m pytest tests src/*/tests --junitxml=test-results/junit.xml
coverage html -d coverage-html
- store_artifacts:
path: test-results
destination: test-results
- store_artifacts:
path: coverage-html
destination: coverage-htmlTo auto-format code with ruff:
uvx ruff format .- Performs basic arithmetic
- Checks division by zero
- Fully tested and type annotated
- Logs messages into an in-memory list
- Fully type-annotated
- Interface abstraction
- Triggers when a value exceeds a threshold
- Tracks state using
was_notified()
.gitignoreexcludes only relevant Python and coverage files- No JS-related or extra entries
This project is licensed under the MIT License. See LICENSE for details.