Python & FastAPI Best Practices (2026): uv, Ruff & Agent Skills

Modern Python backends rely on uv lockfiles, Ruff linting, Pydantic v2 models, and non-blocking async FastAPI handlers. Use this checklist for AI services and APIs, or inspect the official FastAPI, Astral, and Qdrant SKILL.md repositories linked below.

Updated: 2026-11-21 · Works with Claude Code, Cursor, Codex, and Windsurf

Quick Reference Checklist

Core Python & FastAPI Best Practices

01

Use uv and pyproject.toml instead of global pip and requirements.txt

Pin reproducible dependencies with uv.lock and pyproject.toml so local dev, CI, and container builds resolve identical package graphs in seconds.

Avoid:pip install fastapi uvicorn && pip freeze > requirements.txt
Prefer:uv init && uv add fastapi pydantic-settings && uv run pytest
02

Keep blocking I/O out of async def FastAPI routes

Use async drivers (httpx, asyncpg) inside async def handlers, or declare regular def routes so FastAPI offloads blocking calls to its threadpool.

Avoid:async def fetch(): return requests.get(url).json()
Prefer:async def fetch(client: httpx.AsyncClient): return (await client.get(url)).json()
03

Validate config and request payloads with Pydantic v2 models

Define strict BaseModel schemas for request/response contracts and pydantic-settings for environment variables so bad config fails at startup.

Avoid:api_key = os.getenv("OPENAI_KEY"); payload = await request.json()
Prefer:class Settings(BaseSettings): openai_key: SecretStr
04

Inject database sessions and auth via Depends, not global singletons

Use FastAPI dependency injection with yield lifecycles so tests override dependencies cleanly and sessions close after every request.

Avoid:db = SessionLocal() # module-level shared session
Prefer:def get_db(): with SessionLocal() as db: yield db
05

Type-annotate public functions and check with ty or mypy

Add Python 3.12+ native type hints (list[str], str | None) and run static type checking alongside Ruff so contract bugs fail before deploy.

Avoid:def summarize(items, limit=None):
Prefer:def summarize(items: Sequence[Document], limit: int | None = None) -> Summary:
06

Gate changes with Ruff format, Ruff check, and pytest

Run fast lint, format, type, and test gates after every coding agent edit so broken imports and regressions never land.

Avoid:python main.py (manual smoke test)
Prefer:uv run ruff check . && uv run ruff format --check . && uv run pytest

Open-Source Python & FastAPI Agent Skills (8)

Showing 8 of 8 verified skillsStandard: SKILL.md specification
Skill & PublisherStarsInstall
by FastAPI•python

Official MIT-licensed skill maintained inside fastapi/fastapi covering async vs sync route design, Depends lifecycles, Pydantic v2 validation, OpenAPI schemas, and streaming responses.

★ 104,995
by TestMu AI (LambdaTest)•python

MIT-licensed Python testing skill from LambdaTest (TestMu AI) teaching coding agents clean pytest fixtures, parametrized edge cases, monkeypatch mocking, and async FastAPI tests.

★ 393
by Astral•python

Official Apache-2.0 skill from Astral teaching coding agents to manage Python dependencies, lockfiles, tool runs, and isolated scripts with uv instead of brittle global pip commands.

★ 321
by Astral•python

Official Apache-2.0 skill from Astral guiding coding agents to configure Ruff rule sets, run ruff check and ruff format gates, and fix Python lint issues cleanly.

★ 321
by Astral•python

Official Apache-2.0 skill from Astral teaching coding agents how to run ty type checks, resolve Python annotation mismatches, and tighten typing rules in CI.

★ 321
by Qdrant•python

Official Apache-2.0 skill from Qdrant guiding coding agents through collection schemas, batch upserts, payload filtering, and low-latency vector retrieval in AI backends.

★ 271
by Will McGinnis•python

Audited MIT-licensed Python engineering skill covering progressive disclosure, naming conventions, fail-loud error handling, clean __all__ exports, and testing public import paths.

★ 117
by l-mb (Community)•python

Audited MIT-licensed refactoring skill coordinating phased Python analysis, complexity reduction, modern syntax upgrades, and regression-safe test verification.

★ 58

Building with Python & FastAPI and an AI coding agent?

Builderthread pairs verified skills with a private GitHub starter repo, living PRD, and MCP task board for Claude Code, Cursor, and Codex.

Frequently Asked Questions

Questions about Python & FastAPI Best Practices & Skills

What is the recommended modern Python toolchain for AI coding agents in 2026?

Use uv for project and dependency management, Ruff for linting and formatting, ty or mypy for type checking, Pydantic v2 for validation, FastAPI for async APIs, and pytest for automated tests.

Which official Python SKILL.md repositories exist on GitHub?

FastAPI publishes an official skill in fastapi/fastapi, Astral publishes official skills for uv, ruff, and ty in astral-sh/agent-plugins, and Qdrant publishes vector-search client skills in qdrant/skills.

Why do async FastAPI apps stall when written by generic coding agents?

Generic prompts often mix synchronous libraries like requests or psycopg2 inside async def routes, blocking the ASGI event loop. FastAPI and Python API skills enforce async clients or sync route definitions with dependency injection.

Python AI starter + MCP tasks

Ship your Python AI backend from a working baseline

Get a private FastAPI repo with hashed API keys, streaming endpoints, Alembic migrations, and pytest configured, plus a living PRD and verified build tasks for your coding agent.

Six private starter repos, one MCP workflow
Next.js SaaS
Hono API
FastAPI AI
Expo mobile
Tauri Rust
Chrome extension
100% code ownership in your GitHubLiving PRD + MCP task boardStarts at $29 one-time
Start my Python AI repoTry free architecture preview

Free preview needs no signup or card