Python Web Rules
by mochalatte
Production-grade rules for Django and FastAPI to fix N+1 queries, async blocking, and security leaks.
Secure checkout via Stripe
Works with the AI tools you already use
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
- main.py — ORM rule 1. Accessing shipping status in a loop creates an N+1 query pattern.
- 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
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_relatedorprefetch_relatedjoins. - Detects synchronous calls like
requestsor ORM operations insideasynchandlers 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
- 30-day refund guarantee
- One-time purchase, yours forever
- Secure checkout via Stripe
Frequently Asked Questions
Popular in AI Agents & LLM Ops
agentic-workflow
A risk-aware, evidence-based engineering lifecycle protocol for robust agentic task execution and safety.
designing-hybrid-context-layers
Architects the right retrieval strategy for every query — teaching your agent when to use RAG, a knowledge graph, or a temporal index instead of defaulting to vector search for everything.
Open Browser Use
Automate real Chrome profiles with a professional CLI, SDK, and MCP-ready automation stack for AI agents.

skill miner
Analyzes your agent conversation history to find and automate your most frequent recurring tasks.