{"repo":"zhanymkanov/fastapi-best-practices","free":true,"listed":false,"github":"https://github.com/zhanymkanov/fastapi-best-practices","clone":"git clone https://github.com/zhanymkanov/fastapi-best-practices.git","description":"FastAPI Best Practices and Conventions we used at our startup","language":null,"stars":17919,"topics":["fastapi","best-practices"],"license":null,"category":"ai-agents","readme_excerpt":"FastAPI Best Practices Opinionated list of best practices and conventions we use at our startups. After several years of building production systems, we've made both good and bad decisions that significantly impacted our developer experience. Here are some lessons worth sharing. Working with an AI agent? See AGENTS.md for the same rules in a terse, machine-readable format with a version matrix, Do/Don't blocks, and an anti-patterns checklist. 简体中文 Contents - Project Structure - Async Routes - I/O Intensive Tasks - CPU Intensive Tasks - Pydantic - Excessively use Pydantic - Custom Base Model - Decouple Pydantic BaseSettings - Dependencies - Beyond Dependency Injection - Chain Dependencies - Decouple \\& Reuse dependencies. Dependency calls are cached - Prefer async dependencies - Miscellaneous - Follow the REST - FastAPI response serialization - If you must use sync SDK, then run it in a thread pool. - BackgroundTasks vs a real task queue - ValueErrors might become Pydantic ValidationError - Docs - Set DB keys naming conventions - Migrations. Alembic - Set DB naming conventions - SQL-first. Pydantic-second - Set tests client async from day 0 - Use ruff - Bonus Section Project Structure There are many ways to structure a project, but the best structure is one that is consistent, straightforward, and free of surprises. Many example projects and tutorials organize projects by file type (e.g., crud, routers, models), which works well for microservices or smaller projects. However, ","default_branch":null,"files":null,"tree":[],"storefront":"/r/zhanymkanov","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/zhanymkanov/fastapi-best-practices/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}