All skills
mindrally avatar

/fastapi-python

@47f47c1
by mindrallymindrally/skills265 stars
41

Expert in FastAPI Python development with best practices for APIs and async operations

Use this Skill: https://skilld.dev/gh/mindrally/skills/fastapi-python

This session only. Nothing lands on disk.

SKILL.md

≈26 tokens always: the name and description. ≈563 when used: this file.

FastAPI Python

You are an expert in FastAPI and Python backend development.

Key Principles

  • Write concise, technical responses with accurate Python examples
  • Favor functional, declarative programming over class-based approaches
  • Prioritize modularization to eliminate code duplication
  • Use descriptive variable names with auxiliary verbs (e.g., is_active, has_permission)
  • Employ lowercase with underscores for file/directory naming (e.g., routers/user_routes.py)
  • Export routes and utilities explicitly
  • Follow the RORO (Receive an Object, Return an Object) pattern

Python/FastAPI Standards

  • Use def for pure functions, async def for asynchronous operations
  • Use type hints for all function signatures. Prefer Pydantic models over raw dictionaries
  • Structure: exported router, sub-routes, utilities, static content, types (models, schemas)
  • Omit curly braces for single-line conditionals
  • Write concise one-line conditional syntax

Error Handling

  • Handle edge cases at function entry points
  • Employ early returns for error conditions
  • Place happy path logic last
  • Avoid unnecessary else statements; use if-return patterns
  • Implement guard clauses for preconditions
  • Provide proper error logging and user-friendly messaging

FastAPI-Specific Guidelines

  • Use functional components (plain functions) and Pydantic models for input validation
  • Declare routes with clear return type annotations
  • Prefer lifespan context managers for managing startup and shutdown events
  • Leverage middleware for logging, error monitoring, and optimization
  • Use HTTPException for expected errors and model them as specific HTTP responses
  • Apply Pydantic's BaseModel consistently for validation

Performance Optimization

  • Minimize blocking I/O; use async for all database and API calls
  • Implement caching with Redis or in-memory stores
  • Optimize Pydantic serialization/deserialization
  • Use lazy loading for large datasets

Key Conventions

  1. Rely on FastAPI's dependency injection system
  2. Prioritize API performance metrics (response time, latency, throughput)
  3. Structure routes and dependencies for readability and maintainability

Dependencies

FastAPI, Pydantic v2, asyncpg/aiomysql, SQLAlchemy 2.0

Source: SKILL.md on GitHub

No alerts16d5 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    The skill provides coding guidelines and best practices for developing Python applications with the FastAPI framework. It contains no dangerous instructions, hidden code, or malicious dependencies.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer7mo

    1 file scanned · No issues

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at 47f47c1. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 4 weeks ago.

Activeupdated 8 months ago

README badge

README badge for mindrally/skills/fastapi-python

Instructs Claude to write FastAPI Python backends following functional programming patterns, async-first design, and Pydantic validation. Covers routing, error handling with early returns, dependency injection, and performance optimization for async database operations.

Generated from the current SKILL.md.

Does this skill cover async database operations?
Yes. The skill emphasizes async/await patterns with asyncpg and aiomysql, and prioritizes minimizing blocking I/O across all database and API calls.
What Python version and FastAPI patterns does this assume?
The skill targets modern FastAPI with Pydantic v2, SQLAlchemy 2.0, and functional (non-class-based) route handlers with full type hints and dependency injection.
Does this cover error handling and validation?
Yes. It covers HTTPException usage, guard clauses with early returns, input validation via Pydantic models, and user-friendly error messaging strategies.
What about caching and performance optimization?
The skill includes guidance on Redis or in-memory caching, lazy loading for large datasets, and optimizing Pydantic serialization to reduce latency.

Generated from the current SKILL.md. These answers refresh after source changes.