main
Python Skill
Modern Python development guidance using uv, ruff, mypy, and pytest.
Overview
This skill provides comprehensive guidance for Python development following 2025 best practices with modern tooling:
- uv: Fast, all-in-one package manager (replaces pip, poetry, pyenv, virtualenv)
- ruff: Lightning-fast linter and formatter (replaces Black, isort, flake8, pylint)
- mypy: Static type checker for type safety
- pytest: Feature-rich testing framework
Workflows
Project Management
- Project: Create and configure Python projects
- Script: Single-file scripts with PEP 723 inline metadata
- Workspace: Manage monorepos with multiple packages
Code Quality
- Lint: Lint and format code with ruff
- Type: Type check with mypy
- Test: Run tests with pytest and coverage
Dependencies
Tools
python-lint
Run ruff linter and formatter on your code:
./tools/python-lint [directory]
python-check
Run all quality checks (lint, type check, tests):
./tools/python-check [directory]
Quick Start
New Project
# Create project
uv init myproject
cd myproject
# Add dependencies
uv add requests pydantic rich
uv add --dev pytest ruff mypy
# Run checks
uv run ruff check --fix .
uv run ruff format .
uv run mypy .
uv run pytest
Single Script
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "requests>=2.31.0",
# ]
# ///
import requests
def main() -> int:
response = requests.get("https://api.github.com")
print(response.json())
return 0
if __name__ == "__main__":
import sys
sys.exit(main())
chmod +x script.py
./script.py # uv handles dependencies automatically!
Key Features
PEP 723 Support
Inline script metadata allows standalone scripts to declare dependencies directly in the file. No separate requirements.txt needed!
Modern Type Hints
Full support for Python 3.10+ type syntax:
def process(items: list[str], config: dict[str, int] | None = None) -> list[int]:
"""Process items with optional config."""
pass
Fast Tooling
- uv is 10-100x faster than pip
- ruff is 10-100x faster than traditional linters
- Both written in Rust for maximum performance
Best Practices
- Use uv for everything - Package management, venv, running scripts
- Type hints everywhere - Enable mypy strict mode
- Lint with ruff - Auto-fix before committing
- Test with pytest - Aim for >80% coverage
- Lock dependencies - Commit uv.lock to git
- Use PEP 723 - For single-file scripts
- Follow src layout - Place code in
src/package/
Resources
Documentation
- uv Documentation
- PEP 723 - Inline Script Metadata
- Ruff Documentation
- mypy Documentation
- pytest Documentation