Python Web Rules

    by mochalatte

    1

    Production-grade rules for Django and FastAPI to fix N+1 queries, async blocking, and security leaks.

    Secure checkout via Stripe

    0 installsSecurity scanned

    Works with the AI tools you already use

    CClaude CodeCCursorCCodex CLIGGitHub CopilotGGemini CLI+17 more

    See it in action

    You say

    My FastAPI endpoint is slow. It takes a user ID, fetches their profile, then loops through their 50 most recent orders to fetch shipping status from another table, and returns the whole dict.

    Your agent does

    Surface

    FastAPI endpoint fetching User, Order, and Shipping status.

    Findings

    1. main.py — ORM rule 1. Accessing shipping status in a loop creates an N+1 query pattern.
    2. main.py — Pydantic rule 4. Returning a raw dict instead of a response model risks leaking internal DB fields.

    Patch

    @app.get("/orders", response_model=List[OrderResponse]) async def get_orders(user_id: int, db: Session = Depends(get_db)): return ( db.query(Order) .filter(Order.user_id == user_id) .options(joinedload(Order.shipping)) .limit(50) .all() )

    Checks to run

    • Enable SQL logging and confirm exactly 1 query is emitted.
    • Verify OrderResponse excludes internal metadata.

    What you get

    Eliminate N+1 query bottlenecks in Django and FastAPI ORM calls.Prevent event loop lag by moving sync work to thread pools.Secure API endpoints by enforcing strict Pydantic validation models.Correct transaction boundaries to prevent partial database writes.

    About this skill

    The problem

    Python web code often looks correct in development but fails under load due to N plus one queries, blocked event loops, or leaky serialization. LLMs usually write code that works in isolation but ignores production-critical details like transaction boundaries and connection pooling.

    What it does

    • Identifies N plus one query patterns and converts them to select_related or prefetch_related joins.
    • Detects synchronous calls like requests or ORM operations inside async handlers that block the event loop.
    • Enforces Pydantic v2 strictness by separating input/output models and forbidding extra fields to prevent data leaks.
    • Audit settings for security vulnerabilities including missing CSRF protection, exposed secrets, and improper HSTS headers.
    • Refactors database writes to use atomic boundaries and prevents external API calls from holding row locks.

    Frameworks & tools

    Django, FastAPI, Pydantic v2, SQLAlchemy, and standard Python async libraries.

    Why this beats prompting it yourself

    Generic prompts often miss the nuances of database connection lifetimes and background task safety. This skill uses a specific trigger matrix to catch silent failures, like summing columns in Python memory instead of the database, that typical AI suggestions overlook.

    Use cases

    • Refactoring slow Django endpoints that perform hundreds of database queries per request.
    • Converting synchronous FastAPI endpoints to safe asynchronous implementations without blocking.
    • Hardening API security by implementing strict Pydantic validation and secure header configurations.
    • Ensuring database integrity by correctly placing transaction boundaries around multi-row writes.

    Known limitations

    Does not execute migrations, start servers, or access live databases. All verification steps are provided as commands for the user to run manually.

    How to install

    Drop the file into your AI Agent. Works with Claude, Cursor, ChatGPT, and 20+ more.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill passes our trust checks below.

    Security scanned

    Passed our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    30-day refund

    Not a fit? Get your money back

    Trust & safety

    Security scanned

    Verified clean today

    Listedtoday

    Frequently Asked Questions

    Popular in AI Agents & LLM Ops