- Home
- Skills
- APIs & Backend
- FastAPI Backend: Production-Ready Python APIs
FastAPI Backend: Production-Ready Python APIs
by Ignasi
Build production-ready, async FastAPI backends with SQLAlchemy 2.0, Pydantic v2, and layered architecture.
Free
FastAPI Backend: Production-Ready Python APIs
Example session with this skill installed
Create a new FastAPI resource for 'Products' with async SQLAlchemy models, Pydantic v2 schemas for CRUD, and a service layer. Include an endpoint for paginated listing.
- Read your context and instructions
- Compiled the fastapi backend
I have generated the Products resource following the structured service-layer pattern. This includes the database model with SQLAlchemy 2.0 typed mappings, Pydantic v2 schemas (Create, Update, Read), and a service layer to handle the business logic and pagination.
Products Resource Implementation
app/models/product.py
from sqlalchemy.orm import Mapped, mapped_column
from app.db.base import Base
class Product(Base):
__tablename__ = "products"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(index=True)
price: Mapped[float]
is_active: Mapped[bool] = mapped_column(default=True)
app/schemas/product.py
from pydantic import BaseModel, ConfigDict
class ProductBase(BaseModel):
name: str
price: float
class ProductCreate(ProductBase):
pass
class ProductRead(ProductBase):
id: int
model_config = ConfigDict(from_attributes=True)
class ProductPagination(BaseModel):
items: list[ProductRead]
total: int
app/api/v1/routes/products.py
| Method | Path | Auth | Status |
|---|---|---|---|
| GET | /products/ | None | 200 |
| POST | /products/ | JWT | 201 |
| GET | /products/{id} | None | 200 |
| DELETE | /products/{id} | JWT | 204 |
Next steps
- Run
alembic revision --autogenerate -m "add_products_table"to generate the migration. - Add the
product_routerto the main app factory inapp/main.py. - Run
pytest tests/test_products.pyto verify the CRUD logic.
Connects securely to your tools. The creator never sees your data.
About this skill
Building a production-ready FastAPI backend often results in messy async code, tight coupling between models and routes, and inconsistent error handling. This skill enforces a strict architectural pattern using SQLAlchemy 2.0, Pydantic v2, and async best practices to deliver typed, testable, and maintainable Python APIs.
What it does
- Project Scaffolding creates a clean directory structure separating schemas, models, services, and routes.
- Async Execution prevents thread blocking by enforcing async drivers and proper use of
run_in_threadpool. - Database Layering implements SQLAlchemy 2.0 typed mappings, Alembic migrations, and optimized loading strategies.
- Security & Auth configures JWT/OAuth2 flows, argon2 hashing, and object-level permission checks to prevent IDOR.
- Testing Suite generates pytest configurations using
httpx.AsyncClientwith transactional database rollbacks.
How it works
- Initialize the project layout with the app factory, lifespan handlers, and Pydantic settings.
- Define schemas and models using
Mappedtypes andConfigDictfor ORM compatibility. - Implement business logic in service layers, keeping routes lean and focused on HTTP concerns.
- Deploy using multi-stage Dockerfiles optimized with the
uvpackage manager and structured JSON logging.
Frameworks & tools
Python 3.10+, FastAPI, Pydantic v2, SQLAlchemy 2.0 (asyncpg), Alembic, Pytest, Ruff, and UV.
Why this beats prompting it yourself
Most LLMs default to outdated FastAPI patterns like on_event or mixed sync/async code that causes production bottlenecks. This skill enforces strict separation of concerns and Pydantic v2 standards, ensuring your API doesn't leak ORM objects or fail under high concurrency.
Use cases
- Scaffold a new microservice with a complete Auth and DB boilerplate.
- Refactor a blocking Flask or Django REST API into a non-blocking FastAPI service.
- Add resource-level authorization and pagination to existing endpoints.
- Generate a robust test suite covering 422 validation and 401 auth failures.
Known limitations
Does not support synchronous database drivers or deprecated Pydantic v1 syntax. Requires manual review of Alembic autogenerated migrations for complex schema changes.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
1 use
Times used to date
Free to use
No account required to browse
Trust & safety
Security scan
Security scan passed 11 days ago
- Free with an Agensi account
Permissions
What's inside
Frequently Asked Questions
New in APIs & Backend
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.