This template is a lean starting point for Python projects that use:
- ✅ Ruff – formatting & linting
- 🧪 Pytest – testing
- ⚙️ Pydantic Settings – typed environment configuration
- 📦 uv – fast dependency management / locking
- 📝 structlog – structured logging
- 🔍 ty – fast type checking (Rust-powered)
-
Create & Activate Virtual Environment:
# Create the virtual environment using uv uv venv # Activate it (on macOS/Linux) source .venv/bin/activate # On Windows, use: .venv\Scripts\activate
This creates a
.venvdirectory in your project. -
Install Dependencies:
# Installs core + dev dependencies into your active venv make setup -
Run the Application:
# This will use your activated environment make run -
Run Quality Checks:
make format && make lint && make test
src/templates_python/main.py is a minimal entry point with structured logging. Modify it to build your application.
| Command | Description |
|---|---|
make install |
Install core dependencies |
make install-dev |
Install core + dev dependencies |
make setup |
Install dependencies + pre-commit hooks |
make format |
Format code with Ruff |
make lint |
Run Ruff linter |
make typecheck |
Run ty type checker |
make test |
Run Pytest |
make clean |
Remove *.pyc & cache directories |
make lock-check |
Assert uv.lock is in sync |
src/templates_python/utils/settings.py reads variables from a .env file or the environment.
| Variable | Default | Description |
|---|---|---|
LOG_LEVEL |
INFO |
DEBUG, INFO, WARNING, ERROR |
LOG_FORMAT |
console |
console (colored) or json. |
See .env.example for a template.
Only what you need, nothing more:
├── src/
│ └── templates_python/
│ ├── main.py # Main application entry point
│ └── utils/
│ └── settings.py # Pydantic Settings helper
├── tests/
│ └── test_settings.py # Settings validation tests
├── Makefile # Workflow commands
├── pyproject.toml # Project + dependency config
├── uv.lock # Locked dependency versions
└── .github/workflows/ # CI (lint + typecheck + test)
This template includes an optional ML dependency group for data science and machine learning projects:
# Install with ML dependencies
uv sync --extra mlIncludes: PyTorch, scikit-learn, MLflow, matplotlib, numpy, pandas, and seaborn.
This template uses ty, Astral's fast type checker written in Rust.
Note: ty is in alpha and under active development. While production use is not yet recommended, it's suitable for experimentation and early adoption.
# Run ty type checker
make typecheckConfiguration is in pyproject.toml under [tool.ty].
This project uses 2-space indentation and single quotes (configured in Ruff). While Python conventionally uses 4-space indentation, 2-space is a deliberate choice for more compact code. The formatter enforces this automatically.
Key style settings:
- Indent: 2 spaces
- Quotes: Single (
') - Line length: 88 characters
When copying this template into a new project, update:
[project] name,description,authors, andversioninpyproject.toml- The import package name under
src/(renametemplates_python/to your project slug) - The CLI entry in
[project.scripts]
MIT