FastAPI
This skill should be used when the user asks about "FastAPI", "FastAPI routes", "FastAPI dependencies", "Pydantic models", "FastAPI middleware", "API endpoints", "OpenAPI", or mentions FastAPI development.
What this skill does
# FastAPI Development Guidance for building APIs with FastAPI following best practices. --- ## Core Concepts ### Route Decorators | Decorator | HTTP Method | Use Case | |-----------|-------------|----------| | `@app.get()` | GET | Retrieve data | | `@app.post()` | POST | Create resource | | `@app.put()` | PUT | Full update | | `@app.patch()` | PATCH | Partial update | | `@app.delete()` | DELETE | Remove resource | ### Response Status Codes | Code | Meaning | When to Use | |------|---------|-------------| | **200** | OK | Successful GET/PUT/PATCH | | **201** | Created | Successful POST | | **204** | No Content | Successful DELETE | | **400** | Bad Request | Invalid input | | **401** | Unauthorized | Authentication required | | **403** | Forbidden | No permission | | **404** | Not Found | Resource doesn't exist | | **422** | Unprocessable | Validation failed | --- ## Dependency Injection **Key concept**: Dependencies are functions that FastAPI calls before your route handler. Use `yield` for cleanup logic. | Pattern | Use Case | |---------|----------| | **Simple function** | Get config, compute values | | **Generator (yield)** | Database sessions, connections | | **Class-based** | Complex dependencies with state | | **Nested dependencies** | Dependencies that depend on other dependencies | ### Common Dependencies | Dependency | Purpose | |------------|---------| | **get_db** | Database session (yield for cleanup) | | **get_current_user** | Authentication + user retrieval | | **get_settings** | Configuration singleton | | **rate_limiter** | Request throttling | **Key concept**: Use `Annotated[Type, Depends(func)]` for cleaner type hints and reusability. --- ## Pydantic Models ### Model Patterns | Pattern | Purpose | |---------|---------| | **Base model** | Shared fields | | **Create model** | Input for POST (no id) | | **Update model** | Partial updates (all Optional) | | **Response model** | Output (includes id, timestamps) | | **DB model** | Internal with `from_attributes = True` | ### Validation Features | Feature | Purpose | |---------|---------| | **Field(...)** | Required with constraints | | **Field(default=...)** | Optional with default | | **field_validator** | Custom validation logic | | **model_validator** | Cross-field validation | | **pattern=** | Regex validation | | **ge=, le=** | Numeric bounds | | **min_length=, max_length=** | String/list length | --- ## Error Handling | Approach | Use Case | |----------|----------| | **HTTPException** | Simple errors with status code | | **Custom exception class** | Structured error responses | | **@app.exception_handler** | Global error handling | | **RequestValidationError** | Customize validation errors | **Key concept**: Create custom exception classes for consistent error response format across your API. --- ## Router Organization | Concept | Purpose | |---------|---------| | **APIRouter** | Group related endpoints | | **prefix** | URL prefix for all routes | | **tags** | OpenAPI documentation grouping | | **dependencies** | Router-level dependencies | ### Project Structure | Directory | Contents | |-----------|----------| | **routers/** | Route handlers by domain | | **models/** | SQLAlchemy/database models | | **schemas/** | Pydantic request/response models | | **services/** | Business logic | | **dependencies.py** | Shared dependencies | | **config.py** | Settings and configuration | --- ## Background Tasks | Method | Use Case | |--------|----------| | **BackgroundTasks** | Simple async tasks (email, logging) | | **Celery** | Heavy tasks, retries, scheduling | | **ARQ** | Async Redis queue | **Key concept**: BackgroundTasks run after response is sent—good for non-critical operations that shouldn't block the response. --- ## Testing Patterns | Client | Use Case | |--------|----------| | **TestClient** | Sync tests (most common) | | **AsyncClient (httpx)** | Async tests, lifespan events | ### Dependency Override Pattern 1. Create test version of dependency 2. Set `app.dependency_overrides[original] = test_version` 3. Run tests 4. Clear overrides after **Key concept**: Override `get_db` for test database, `get_current_user` for auth bypass. --- ## Best Practices | Practice | Why | |----------|-----| | Use response_model | Control output, hide internal fields | | Use dependency injection | Testable, reusable code | | Separate schemas from DB models | Decouple API from database | | Use routers for organization | Maintainable as API grows | | Add OpenAPI descriptions | Self-documenting API | | Use async for I/O | Better concurrency | ## Resources - Docs: <https://fastapi.tiangolo.com/> - Tutorial: <https://fastapi.tiangolo.com/tutorial/>
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.