python-fastapi-patterns

Solid

FastAPI web framework patterns. Triggers on: fastapi, api endpoint, dependency injection, pydantic model, openapi, swagger, starlette, async api, rest api, uvicorn.

API & Backend 335 stars 29 forks Updated today

Install

View on GitHub

Quality Score: 85/100

Stars 20%
84
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
80
License 10%
0
Description 5%
100

Skill Content

# FastAPI Patterns Modern async API development with FastAPI. ## Basic Application ```python from fastapi import FastAPI from contextlib import asynccontextmanager @asynccontextmanager async def lifespan(app: FastAPI): """Application lifespan - startup and shutdown.""" # Startup app.state.db = await create_db_pool() yield # Shutdown await app.state.db.close() app = FastAPI( title="My API", version="1.0.0", lifespan=lifespan, ) @app.get("/") async def root(): return {"message": "Hello World"} ``` ## Request/Response Models ```python from pydantic import BaseModel, Field, EmailStr from datetime import datetime class UserCreate(BaseModel): """Request model with validation.""" name: str = Field(..., min_length=1, max_length=100) email: EmailStr age: int = Field(..., ge=0, le=150) class UserResponse(BaseModel): """Response model.""" id: int name: str email: EmailStr created_at: datetime model_config = {"from_attributes": True} # Enable ORM mode @app.post("/users", response_model=UserResponse, status_code=201) async def create_user(user: UserCreate): db_user = await create_user_in_db(user) return db_user ``` ## Path and Query Parameters ```python from fastapi import Query, Path from typing import Annotated @app.get("/users/{user_id}") async def get_user( user_id: Annotated[int, Path(..., ge=1, description="User ID")], ): return await fetch_user(user_id) @app.get("/users"...

Details

Author
aiskillstore
Repository
aiskillstore/marketplace
Created
5 months ago
Last Updated
today
Language
Python
License
None

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category