agentleFS
ishandutta0098ishandutta0098/outskill/.cursor/rules/fastapi-python-cursor-rules.mdc

outskill / rules

Cursor rule465 starsChanged 7 months agoMITView on GitHub

You are an expert in Python, FastAPI, and scalable API development. Key Principles - Write concise, technical responses with accurate Python examples. - Use functional, declarative programming; avoid classes where possible. - Prefer iteration and modularization over code duplication. - Use descriptive variable names with auxiliary verbs (e.g., is_active, has_permission). - Use lowercase with underscores for directories and files (e.g., routers/user_routes.py). - Favor named exports for routes and utility functions. - Use the Receive an Object, Return an Object (RORO)…

  • Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.

    Of the Cursor rule files we read, the 4,157 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repository2 other files it gives its agents.

The file

Show its rules and text

We split this fastapi-python-cursor-rules.mdc into the rules it gives an agent

24 rules. About 0 are common, 23 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈23

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Write concise, technical responses with accurate Python examples.

    line 8
  2. Distinctive:

    Use functional, declarative programming.

    line 9
  3. Distinctive:

    Prefer iteration and modularization over code duplication.

    line 10
  4. Distinctive:

    Use descriptive variable names with auxiliary verbs (e.g., is_active, has_permission).

    line 11
  5. Very specific:

    Use lowercase with underscores for directories and files (e.g., routers/user_routes.py).

    line 12
  6. Distinctive:

    Use the Receive an Object, Return an Object (RORO) pattern.

    line 14
  7. Distinctive:

    Use def for pure functions and async def for asynchronous operations.

    line 17
  8. Distinctive:

    Use type hints for all function signatures.

    line 18
  9. Distinctive:

    Avoid unnecessary curly braces in conditional statements.

    line 20
  10. Distinctive:

    Use concise, one-line syntax for simple conditional statements (e.g., if condition: do_something()).

    line 22
  11. Distinctive:

    Use early returns for error conditions to avoid deeply nested if statements.

    line 27
  12. Distinctive:

    Place the happy path last in the function for improved readability.

    line 28
  13. Distinctive:

    Avoid unnecessary else statements.

    line 29
  14. Distinctive:

    Use guard clauses to handle preconditions and invalid states early.

    line 30
  15. Distinctive:

    Use custom error types or error factories for consistent error handling.

    line 32
  16. Distinctive:

    Use functional components (plain functions) and Pydantic models for input validation and response schemas.

    line 41
  17. Distinctive:

    Use declarative route definitions with clear return type annotations.

    line 42
  18. Distinctive:

    Use def for synchronous operations and async def for asynchronous ones.

    line 43
  19. Distinctive:

    Use middleware for logging, error monitoring, and performance optimization.

    line 45
  20. Distinctive:

    Use HTTPException for expected errors and model them as specific HTTP responses.

    line 47
  21. Distinctive:

    Use middleware for handling unexpected errors, logging, and error monitoring.

    line 48
  22. Distinctive:

    Use Pydantic's BaseModel for consistent input/output validation and response schemas.

    line 49
  23. Distinctive:

    Use lazy loading techniques for large datasets and substantial API responses.

    line 55
  24. Distinctive:

    Use dedicated async functions for database and external API operations.

    line 62

≈ “Common” is an estimate: at least 1 in 5 of the 6,668 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
fastapi-python-cursor-rules.mdc
---
alwaysApply: true
---

You are an expert in Python, FastAPI, and scalable API development.
  
  Key Principles
  - Write concise, technical responses with accurate Python examples.
  - Use functional, declarative programming; avoid classes where possible.
  - Prefer iteration and modularization over code duplication.
  - Use descriptive variable names with auxiliary verbs (e.g., is_active, has_permission).
  - Use lowercase with underscores for directories and files (e.g., routers/user_routes.py).
  - Favor named exports for routes and utility functions.
  - Use the Receive an Object, Return an Object (RORO) pattern.
  
  Python/FastAPI
  - Use def for pure functions and async def for asynchronous operations.
  - Use type hints for all function signatures. Prefer Pydantic models over raw dictionaries for input validation.
  - File structure: exported router, sub-routes, utilities, static content, types (models, schemas).
  - Avoid unnecessary curly braces in conditional statements.
  - For single-line statements in conditionals, omit curly braces.
  - Use concise, one-line syntax for simple conditional statements (e.g., if condition: do_something()).
  
  Error Handling and Validation
  - Prioritize error handling and edge cases:
    - Handle errors and edge cases at the beginning of functions.
    - Use early returns for error conditions to avoid deeply nested if statements.
    - Place the happy path last in the function for improved readability.
    - Avoid unnecessary else statements; use the if-return pattern instead.
    - Use guard clauses to handle preconditions and invalid states early.
    - Implement proper error logging and user-friendly error messages.
    - Use custom error types or error factories for consistent error handling.
  
  Dependencies
  - FastAPI
  - Pydantic v2
  - Async database libraries like asyncpg or aiomysql
  - SQLAlchemy 2.0 (if using ORM features)
  
  FastAPI-Specific Guidelines
  - Use functional components (plain functions) and Pydantic models for input validation and response schemas.
  - Use declarative route definitions with clear return type annotations.
  - Use def for synchronous operations and async def for asynchronous ones.
  - Minimize @app.on_event("startup") and @app.on_event("shutdown"); prefer lifespan context managers for managing startup and shutdown events.
  - Use middleware for logging, error monitoring, and performance optimization.
  - Optimize for performance using async functions for I/O-bound tasks, caching strategies, and lazy loading.
  - Use HTTPException for expected errors and model them as specific HTTP responses.
  - Use middleware for handling unexpected errors, logging, and error monitoring.
  - Use Pydantic's BaseModel for consistent input/output validation and response schemas.
  
  Performance Optimization
  - Minimize blocking I/O operations; use asynchronous operations for all database calls and external API requests.
  - Implement caching for static and frequently accessed data using tools like Redis or in-memory stores.
  - Optimize data serialization and deserialization with Pydantic.
  - Use lazy loading techniques for large datasets and substantial API responses.
  
  Key Conventions
  1. Rely on FastAPI’s dependency injection system for managing state and shared resources.
  2. Prioritize API performance metrics (response time, latency, throughput).
  3. Limit blocking operations in routes:
     - Favor asynchronous and non-blocking flows.
     - Use dedicated async functions for database and external API operations.
     - Structure routes and dependencies clearly to optimize readability and maintainability.
  
  Refer to FastAPI documentation for Data Models, Path Operations, and Middleware for best practices.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.