This guide covers Python-specific setup and development in the Centaur template.
uv package manager (installed automatically in devcontainer)Everything is pre-installed. Just run:
cd python
uv sync --all-extras
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# Navigate to Python project
cd python
# Install dependencies
uv sync --all-extras
python/
├── src/
│ └── centaur_example/ # Main package
│ ├── __init__.py
│ ├── calculator.py
│ └── text_utils.py
├── tests/
│ ├── unit/ # Unit tests
│ ├── integration/ # Integration tests
│ └── fuzzing/ # Fuzzing tests
├── pyproject.toml # Project config
├── .python-version # Python version
└── README.md
# All tests
uv run pytest
# With coverage
uv run pytest --cov --cov-report=html
# Specific test types
uv run pytest tests/unit/ -v
uv run pytest tests/integration/ -v
uv run pytest tests/fuzzing/ -v
# Specific test file
uv run pytest tests/unit/test_calculator.py -v
# Specific test function
uv run pytest tests/unit/test_calculator.py::test_add_positive_positive -v
# Linting
uv run ruff check src tests
# Auto-fix linting issues
uv run ruff check --fix src tests
# Formatting
uv run black src tests
# Check formatting only
uv run black --check src tests
# Type checking
uv run mypy src
# Add runtime dependency
uv add requests
# Add development dependency
uv add --dev pytest-benchmark
# Remove dependency
uv remove package-name
# Update all dependencies
uv lock --upgrade
uv sync
Located in tests/unit/, these test individual functions in isolation.
Example:
def test_add_positive_positive() -> None:
"""Test adding two positive numbers."""
assert add(5, 3) == 8
Best practices:
test_<function>_<scenario>Located in tests/integration/, these test components working together.
Example:
def test_chain_operations() -> None:
"""Test chaining multiple operations."""
result = add(5, 3)
result = multiply(result, 2)
assert result == 16
Tests properties that should always hold true.
Example:
from hypothesis import given, strategies as st
@given(st.integers(), st.integers())
def test_add_commutative(a: int, b: int) -> None:
"""Test that addition is commutative."""
assert add(a, b) == add(b, a)
Coverage-guided fuzzing for security testing.
Example:
import atheris
def test_calculator(data: bytes) -> None:
fdp = atheris.FuzzedDataProvider(data)
a = fdp.ConsumeFloat()
b = fdp.ConsumeFloat()
_ = add(a, b)
Key sections:
[project]
name = "your-project-name"
version = "0.1.0"
dependencies = [
# Your runtime dependencies
]
[project.optional-dependencies]
dev = [
# Development dependencies
]
[tool.pytest.ini_options]
# Pytest configuration
[tool.ruff]
# Ruff linter configuration
[tool.black]
# Black formatter configuration
[tool.mypy]
# Type checking configuration
Specifies Python version. uv uses this automatically.
cd python
uv sync
Ensure you’re using uv run:
uv run pytest
# Run type checker
uv run mypy src
# Add type stubs for third-party libraries
uv add --dev types-requests
Extensions are automatically installed in devcontainer:
The .venv should be automatically detected as the Python interpreter.
python/ directorypython/.venv/bin/python