A template for Python project, equipped with best practices, can be used whenever needed.
- Python packaging and dependency management: uv (handles Python installation and virtual environments)
- Dockerfile: test and run codes within container
Makefile: provides shortcuts to making life easierDeprecated, replaced by Task- Task runner Task: easily run pre-defined tasks specified in configuration file Taskfile.yml
- Type checkers:
- Linter & Formatter: Ruff. Rules→here
Code formatter:blackDeprecated, covered by Ruff.Import sorter: isortDeprecated, covered by Ruff.
🩺 Testing framework pytest
- Running test:
pytest ./src/test - Test on specific marker:
pytest ./src/test -m <mark_name> - Test + duration report:
pytest ./src/test --durations=3 - Test + coverage:
pytest --cov=src ./src/test - Test + force coverage:
pytest --cov-fail-under=80 ./src/test
- Run .pre-commit-config.yaml every time before submission to ensure quality
- Install pre-commit: link
- Generate & modify .pre-commit-config.yaml
- Set up the git hook scripts:
pre-commit install
- PR template
- Issue template
- CI workflow
- AGENTS.md - agent instructions for the project
- Github Copilot instructions are added in .github
- Cursor rules are added in .cursor
- Dependency vulnerability check:safety, support CLI and in CI workflow
uv is an extremely fast Python package and project manager that handles both Python installation and dependency management. It's all you need to set up a reproducible development environment for this project.
You can install uv following this link.
Setting up the development environment is simple:
- Install Python and create virtual environment with dependencies:
uv syncThat's it! uv will automatically:
- Install Python 3.12+ if not available (as specified in
pyproject.toml) - Create a virtual environment in
.venv/ - Install all project dependencies and development tools
- Activate the virtual environment:
source .venv/bin/activate- Run commands within the environment:
# Run tests
uv run pytest ./src/test
# Run linting
uv run ruff check
# Add new dependencies
uv add <package-name>
# Add development dependencies
uv add --group dev <package-name>The project uses Task as a task runner. Here are the available commands:
Code Quality:
task linter # Run ruff linter with auto-fix
task linter-watch # Run ruff linter in watch mode
task formatter # Run ruff formatter
task ty-checker # Run ty type checker (fast Rust-based)
task pyrefly-checker # Run pyrefly type checker (advanced analysis)
task precommit # Run all pre-commit hooksTesting:
task run-test # Run test suite in src/test folderDependency Management:
task check_updatable_libs # Check for outdated dependenciesDocker:
task dc-up # Start docker compose services
# Usage: task dc-up PROFILE=<name> BUILD=--build
task dc-exec # Execute command in running container
# Usage: task dc-exec SERVICE=<name> CMD=<command>-
Docker compose for spin-up different components:
- DB
- Kafka
-
CI:
Reference: