build-production-python-apis
Build fast, production-ready Python APIs with type hints, validation, and async support.
от rondoflow★ 37 звёзд на GitHub
Установить build-production-python-apis в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
FastAPI Patterns
Async Traps
- Mixing sync database drivers (psycopg2, PyMySQL) in async endpoints blocks the event loop — use async drivers (asyncpg, aiomysql) or run sync code in
run_in_executor time.sleep()in async endpoints blocks everything — useawait asyncio.sleep()instead- CPU-bound work in async endpoints starves other requests — offload to
ProcessPoolExecutoror background workers - Async endpoints calling sync functions that do I/O still block — the entire call chain must be async
Pydantic Validation
- Default values in models become shared mutable state:
items: list = []shares the same list across requests — useField(default_factory=list) Optional[str]doesn't make a field optional in the request — add= Noneor useField(default=None)- Pydantic v2 uses
model_validate()notparse_obj(), andmodel_dump()not.dict()— v1 methods are deprecated - Use
Annotated[str, Field(min_length=1)]for reusable validated types instead of repeating constraints
Dependency Injection
- Dependencies run on every request by default — use
lru_cacheon expensive dependencies or cache in app.state for singletons Depends()without an argument reuses the type hint as the dependency — clean but can confuse readers- Nested dependencies form a DAG — if A depends on B and C, and both B and C depend on D, D runs once (cached per-request)
yielddependencies for cleanup (DB sessions, file handles) — code after yield runs even if the endpoint raises
Lifespan and Startup
@app.on_event("startup")is deprecated — uselifespanasync context manager- Store shared resources (DB pool, HTTP client) in
app.stateduring lifespan, not as global variables - Lifespan runs once per worker process — with 4 Uvicorn workers you get 4 DB pools
from contextlib import asynccontextmanager
@asynccontextmanager
async def lifespan(app):
app.state.db = await create_pool()
yield
await app.state.db.close()
app = FastAPI(lifespan=lifespan)
Request/Response
- Return
dictfrom endpoints, not Pydantic models directly — FastAPI handles serialization and it's faster - Use
status_code=201on POST endpoints returning created resources — 200 is the default but semantically wrong Responsewithmedia_type="text/plain"for non-JSON responses — returning a string still gets JSON-encoded otherwise- Set
response_model_exclude_unset=Trueto omit None fields from response — cleaner API output
Error Handling
raise HTTPException(status_code=404)— don't return Response objects for errors, it bypasses middleware- Custom exception handlers with
@app.exception_handler(CustomError)— but remember they don't catch HTTPException - Use
detail=for user-facing messages, log the actual error separately — don't leak stack traces
Background Tasks
BackgroundTasksruns after the response is sent but still in the same process — not suitable for long-running jobs- Tasks execute sequentially in order added — don't assume parallelism
- If a background task fails, the client never knows — add your own error handling and alerting
Security
OAuth2PasswordBeareris for documentation only — it doesn't validate tokens, you must implement that in the dependency- CORS middleware must come after exception handlers in middleware order — or errors won't have CORS headers
Depends(get_current_user)in path operation, not in router — dependencies on routers affect all routes including health checks
Testing
TestClientruns sync even for async endpoints — usehttpx.AsyncClientwithASGITransportfor true async testing- Override dependencies with
app.dependency_overrides[get_db] = mock_db— cleaner than monkeypatching TestClientcontext manager ensures lifespan runs — withoutwith TestClient(app) as client:startup/shutdown hooks don't fire
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- manifest.json
FAQ
Что делает скилл build-production-python-apis?
Build fast, production-ready Python APIs with type hints, validation, and async support.
Как установить скилл build-production-python-apis?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл build-production-python-apis запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
AnthropicGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
academy-guide
AnthropicStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
internal-comms
AnthropicA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
skill-development
AnthropicThis skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…