| Tool | Phase | Key commands | Use case |
|---|---|---|---|
| uv | env |
uv python install 3.12
uv init myproject && cd myproject
uv add httpx pytest ruff
uv add --dev pytest-cov mypy
uv sync --frozen
uv run --frozen pytest -x
uv lock --upgrade-package httpx
uv tool install ruff
|
Replaces pip, pip-tools, virtualenv, and pyenv in one binary. --frozen enforces the lockfile. Use in CI always. uv tool install installs CLI tools in isolated envs without polluting the project. Written in Rust; installs in <1s. |
| pyenv | env |
pyenv install 3.12.4
pyenv global 3.12.4
pyenv local 3.11.9
pyenv versions
pyenv which python
# .python-version committed to repo locks CI and local
|
System-level Python version management when uv's bundled interpreter doesn't fit (e.g. specific CPython patch versions, PyPy, GraalPy). .python-version file pins the version per-repo, analogous to .terraform-version. |
| pyproject.toml | packaging |
# minimal PEP 517 layout:
# [build-system]
# requires = ["hatchling"]
# build-backend = "hatchling.build"
#
# [project]
# name = "mypackage"
# version = "0.1.0"
# requires-python = ">=3.12"
# dependencies = ["httpx>=0.27"]
python -c "import tomllib; import sys; tomllib.loads(open('pyproject.toml').read())"
|
Single source of truth for project metadata, dependencies, tool config ([tool.ruff], [tool.mypy], [tool.pytest]). Avoid setup.py and setup.cfg entirely. They're legacy. tomllib is stdlib since 3.11; no extra dep to validate. |
| hatch | packaging |
hatch version
hatch version minor
hatch build
hatch build --target wheel
hatch env show
hatch run test:pytest
hatch run lint:ruff check .
|
PEP 517 build backend + version management + multi-env runner. hatch version minor bumps and writes back to pyproject.toml without sed hacks. Environments defined declaratively: reproducible across machines. Pairs naturally with uv for dep resolution. |
| pip-audit | packaging |
pip-audit
pip-audit -r requirements.txt
pip-audit --fix
pip-audit -f json | jq '.dependencies[] | select(.vulns | length > 0)'
pip-audit --ignore-vuln GHSA-xxxx-xxxx-xxxx
|
PyPA-maintained vulnerability scanner against the Python Packaging Advisory Database and OSV. --fix upgrades vulnerable packages in-place. Analogous to govulncheck for Python: only reports exploitable paths, not all transitive deps. |
| ruff | quality |
ruff check .
ruff check --fix .
ruff check --select ALL --ignore D,ANN .
ruff format .
ruff format --check .
ruff check --output-format github .
# replaces: flake8, isort, pyupgrade, pydocstyle, bandit subsets
|
Replaces flake8 + isort + pyupgrade + pydocstyle in one Rust-native binary. 10 to 100× faster than equivalents. --select ALL then ignore selectively is more maintainable than allowlisting. ruff format replaces black with compatible output. |
| mypy | quality |
mypy src/ --strict
mypy src/ --ignore-missing-imports
mypy src/ --show-error-codes --pretty
mypy src/ --html-report mypy-report/
mypy src/ --incremental
# dmypy for daemon mode (fast re-checks):
dmypy run -- src/
|
Static type checking. --strict enables all optional checks. Use on new projects; too noisy to retrofit all at once on legacy code. dmypy daemon maintains incremental state: re-checks in milliseconds vs seconds for large codebases. |
| pytest | quality |
pytest -x -q
pytest -x --tb=short -q --no-header
pytest -k "test_parse and not slow" -v
pytest --cov=src --cov-report=term-missing --cov-fail-under=80
pytest -n auto
pytest --co -q
# --co: collect-only, lists tests without running
|
-n auto (pytest-xdist) parallelises across CPUs: essential for large test suites. --co validates test collection without running; catch import errors in CI fast. --cov-fail-under gates the build on coverage thresholds. |
| hypothesis | quality |
# in test file:
from hypothesis import given, settings, strategies as st
@given(st.text(), st.integers(min_value=0))
def test_parse_never_crashes(s, n): parse(s, n)
pytest --hypothesis-show-statistics
pytest --hypothesis-seed=0
# replay a failure:
pytest --hypothesis-seed=<reported-seed>
|
Property-based testing: generates adversarial inputs automatically. Finds edge cases unit tests never cover. --hypothesis-seed makes failures reproducible. Integrates with pytest; no separate runner needed. Particularly effective on parsers, serialisers, and data pipelines. |
| maturin | rust / ffi |
maturin init --bindings pyo3
maturin develop --release
maturin develop --extras dev
maturin build --release --strip -i python3.12
maturin build --release --target x86_64-unknown-linux-musl
maturin publish
# produces a .whl with embedded Rust extension
|
Build and publish PyO3/CFFI Rust extensions as Python wheels. maturin develop installs the extension in-place for interactive development: no full rebuild cycle. --strip reduces wheel size significantly. Handles cross-compilation and manylinux compliance. |
| pyo3 | rust / ffi |
# Cargo.toml:
# [lib]
# name = "myext"
# crate-type = ["cdylib"]
# [dependencies]
# pyo3 = { version = "0.21", features = ["extension-module"] }
# src/lib.rs:
# #[pyfunction] fn sum_as_string(a: usize, b: usize) -> String { (a+b).to_string() }
# #[pymodule] fn myext(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_function(wrap_pyfunction!(sum_as_string, m)?)?; Ok(()) }
maturin develop --release
|
Rust bindings for CPython: write performance-critical code in Rust, call it from Python with zero marshalling overhead on primitive types. GIL-aware; supports py.allow_threads() for true parallelism. Pairs with maturin for the build/publish pipeline. |
| cffi / ctypes | rust / ffi |
# build a C-compatible shared lib from Rust:
cargo build --release --lib
# then in Python (ctypes: stdlib):
import ctypes
lib = ctypes.CDLL("./target/release/libmylib.so")
lib.my_func.restype = ctypes.c_uint64
result = lib.my_func(42)
# cffi for more complex ABI, struct layouts:
python -c "import cffi; ffi = cffi.FFI(); ffi.cdef('uint64_t my_func(int);')"
|
When PyO3 is overkill: call any C-ABI shared library directly. ctypes is stdlib; cffi handles complex struct layouts and is faster at runtime. Use for integrating existing C/Rust libs without rewriting them as Python extensions. |
| build | publish |
python -m build
python -m build --wheel
python -m build --sdist
python -m build --outdir dist/
# verify wheel contents before publishing:
python -m zipfile -l dist/mypackage-0.1.0-py3-none-any.whl
|
PyPA's PEP 517 frontend: the correct way to build sdist and wheels. Runs in an isolated build env; never pollutes your dev env. Always build both sdist and wheel; sdist is required for PyPI and enables source installs on unsupported platforms. |
| twine | publish |
twine check dist/*
twine upload --repository testpypi dist/*
twine upload dist/*
twine upload --skip-existing dist/*
# use TWINE_USERNAME=__token__ TWINE_PASSWORD=pypi-... in CI
# never embed tokens in config files
|
twine check validates dist files before upload: catches malformed metadata and README rendering issues. Always upload to TestPyPI first. Use API tokens via env vars, never username/password. --skip-existing makes reruns idempotent in CI. |
| uv in GitHub Actions | ci patterns |
# .github/workflows/ci.yml
- uses: astral-sh/setup-uv@v5
with:
enable-cache: true
- run: uv sync --frozen --all-extras
- run: uv run --frozen ruff check .
- run: uv run --frozen mypy src/ --strict
- run: uv run --frozen pytest -x --cov=src --cov-fail-under=80
|
Full CI pipeline in ~30s. enable-cache: true caches the uv package cache across runs. --frozen everywhere ensures CI uses the committed lockfile exactly. No virtualenv activation needed: uv run resolves the env automatically. |
| maturin in GitHub Actions | ci patterns |
# build wheels for all platforms:
- uses: PyO3/maturin-action@v1
with:
command: build
args: --release --strip --interpreter python3.12
manylinux: auto
# cross-compile for multiple targets:
target: x86_64,aarch64,armv7
|
Official maturin GitHub Action handles manylinux Docker setup, cross-compilation toolchains, and Rust caching automatically. manylinux: auto picks the right manylinux image for broad Linux compatibility. Upload resulting wheels as artifacts, then publish with twine. |
| pre-commit | ci patterns |
pre-commit install
pre-commit run --all-files
pre-commit run ruff --all-files
pre-commit autoupdate
pre-commit run --from-ref origin/main --to-ref HEAD
# in CI without installing hooks:
pre-commit run --all-files --show-diff-on-failure
|
Runs hooks (ruff, mypy, gitleaks, hadolint, terraform fmt) on staged files before commit. --from-ref/--to-ref runs only on changed files in CI: fast. pre-commit autoupdate bumps hook versions; run it periodically and commit the result. |
No tools match this filter.