Modern Python tooling best practices using uv, ruff, ty, and pytest. Mandates the Trail of Bits Python coding standards for project setup, dependency management, linting, type checking, and testing. Based on patterns from trailofbits/cookiecutter-python.
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
Modern Python tooling best practices using uv, ruff, ty, and pytest. Mandates the Trail of Bits Python coding standards for project setup, dependency management, linting, type checking, and testing. Based on patterns from trailofbits/cookiecutter-python.
["Always use uv for dependency management instead of pip/Poetry/pipenv","Use ruff for both linting and formatting instead of separate tools","Use ty for type checking instead of mypy (faster, Rust-based)","Structure tests with pytest and use hypothesis for property-based testing","Configure all tools in pyproject.toml, never in separate config files"]
error_handling
graceful
streaming
supported
verified
true
lastVerifiedAt
2026-03-01
source
builtin
trust_score
100
provenance_sha
8b510b7ff762a6a6
Modern Python Skill
Modern Python tooling skill adapted from Trail of Bits coding standards. Mandates the use of uv (package management), ruff (linting and formatting), ty (type checking), and pytest (testing) as the standard Python toolchain. Based on patterns from trailofbits/cookiecutter-python for consistent, high-quality Python projects.
- Project initialization with modern Python toolchain (uv + ruff + ty + pytest)
- Migration from legacy tools (pip/Poetry/pipenv to uv, black/flake8/isort to ruff, mypy to ty)
- pyproject.toml configuration for all tools (single source of truth)
- Dependency management with uv (lock files, dependency groups, virtual environments)
- Linting and formatting with ruff (replaces flake8, isort, black, pyflakes, pycodestyle)
- Type checking with ty (Rust-based, faster than mypy)
- Testing with pytest, pytest-cov, and hypothesis
- CI/CD configuration with GitHub Actions
- Dependabot setup for automated dependency updates
- Pre-commit hook configuration
Overview
This skill implements Trail of Bits' modern Python coding standards for the agent-studio framework. The core philosophy is: use Rust-based tools for faster feedback loops, especially when working with AI agents. Every tool in this stack (uv, ruff, ty) is written in Rust and provides sub-second execution times, enabling tight iteration cycles.
When migrating Python projects from legacy tooling
When setting up CI/CD pipelines for Python projects
When standardizing Python tooling across a team
When writing standalone Python scripts that need proper structure
When an AI agent needs fast feedback from Python tooling
Iron Laws
ALWAYS configure all Python tooling in pyproject.toml -- no separate config files (setup.cfg, .flake8, mypy.ini, black.toml) are permitted.
ALWAYS use uv add/uv remove for dependency management -- never use bare pip install in projects managed by uv.
NEVER commit venv/, .venv/, or pip-generated requirements.txt -- commit uv.lock for reproducible builds.
ALWAYS use uv run to execute tools and scripts -- this ensures the correct virtual environment and dependency resolution.
NEVER use legacy linting/formatting tools (flake8, black, isort, mypy) when ruff and ty are available -- consolidate to the Rust-based stack for speed and consistency.
Anti-Patterns
Anti-Pattern
Why It Fails
Correct Approach
Using pip install directly in a uv-managed project
Bypasses lockfile and dependency resolution; creates reproducibility drift
Use uv add <pkg> to add dependencies and uv sync to install
Maintaining .flake8, mypy.ini, or black.toml config files
Fragments configuration across multiple files; hard to maintain and audit
Consolidate all tool config into pyproject.toml under [tool.ruff] and [tool.ty]
Running python script.py instead of uv run python script.py
Uses system Python instead of project venv; dependency mismatches
Always use uv run to execute within the managed environment
Globally installing CLI tools with pip install --user
Pollutes global environment; version conflicts across projects
Use uv tool run <tool> or uvx <tool> for one-off tool execution
Ignoring ruff security rules (S select)
Misses bandit-equivalent security checks like hardcoded passwords and SQL injection
Enable select = ["S"] in [tool.ruff.lint] for security linting
# Add a dependency
uv add requests
# Add a dev dependency
uv add --group dev ipdb
# Remove a dependency
uv remove requests
# Update all dependencies
uv lock --upgrade
# Update a specific dependency
uv lock --upgrade-package requests
# Run a script in the project environment
uv run python script.py
# Run a tool (without installing globally)
uv run --with httpie http GET https://api.example.com
Linting and Formatting (ruff)
# Check for lint errors
uv run ruff check .
# Auto-fix lint errors
uv run ruff check --fix .
# Format code
uv run ruff format .
# Check formatting (dry run)
uv run ruff format --check .
# Check specific rules
uv run ruff check --select S . # Security rules only
Type Checking (ty)
# Run type checker
uv run ty check
# Check specific file
uv run ty check src/main.py
Testing (pytest)
# Run all tests
uv run pytest
# Run with coverage
uv run pytest --cov
# Run specific test file
uv run pytest tests/test_auth.py
# Run with verbose output
uv run pytest -v
# Run and stop at first failure
uv run pytest -x
from __future__ import annotations
from collections.abc importSequencefrom typing import TypeAlias
# Use modern syntax (Python 3.12+)type Vector = list[float] # Type alias (PEP 695)defprocess_items(items: Sequence[str], *, limit: int = 10) -> list[str]:
"""Process items with a limit."""return [item.strip() for item in items[:limit]]
# Use | instead of Uniondefmaybe_int(value: str) -> int | None:
try:
returnint(value)
except ValueError:
returnNone
Before starting: Check if the project already has Python tooling configured. Identify which legacy tools need migration.
During setup: Write configuration incrementally, verifying each tool works before moving to the next. Run ruff check, ruff format --check, and uv run pytest at each step.
After completion: Record the toolchain versions and any migration issues to .claude/context/memory/learnings.md for future reference.