Rule

0 installs · 0 said it worked

PatrickJS@patrickjs·
CodingRule· for Cursor

FastAPI best-practices rules for building Python web APIs

Cursor rules file guiding the assistant to follow FastAPI best practices across project structure, API design, Pydantic models, database, auth, security, performance, testing, deployment, and documentation.

People use this for

  • fastapi best practices prompt
  • cursor rules python api
  • fastapi project structure guide
  • write fastapi endpoints with pydantic models
  • help me set up fastapi auth and security
Name
fastapi-best-practices-rules-for-building-python-web-apis
Works with
Cursor
License
CC0(as observed at the source)
Version
v1 · updated Nov 29, 2026
Imported · UnclaimedCC0

Imported on Nov 29, 2026 from github.com . License observed at the source on Nov 29, 2026: CC0.

Are you the author?Claim this profileRequest removal

Use this rule

$ curl -fsSL "https://promptcommunity.dev/api/v1/posts/fastapi-best-practices-rules-for-building-python-web-apis-ssa8/export/mdc" -o .cursor/rules/fastapi-best-practices-rules-for-building-python-web-apis.mdc

Then open a new session; Cursor picks it up from .cursor/rules/.

Download fastapi-best-practices-rules-for-building-python-web-apis.mdc
Manual install

Save fastapi-best-practices-rules-for-building-python-web-apis.mdc as .cursor/rules/fastapi-best-practices-rules-for-building-python-web-apis.mdc for this project or ~/.cursor/rules/fastapi-best-practices-rules-for-building-python-web-apis.mdc for every project, then start a new session.

Rule


description: "FastAPI best practices and patterns for building modern Python web APIs" globs: /*.py, app//.py, api/**/.py alwaysApply: false

FastAPI Best Practices

Project Structure

  • Use proper directory structure
  • Implement proper module organization
  • Use proper dependency injection
  • Keep routes organized by domain
  • Implement proper middleware
  • Use proper configuration management

API Design

  • Use proper HTTP methods
  • Implement proper status codes
  • Use proper request/response models
  • Implement proper validation
  • Use proper error handling
  • Document APIs with OpenAPI

Models

  • Use Pydantic models
  • Implement proper validation
  • Use proper type hints
  • Keep models organized
  • Use proper inheritance
  • Implement proper serialization

Database

  • Use proper ORM (SQLAlchemy)
  • Implement proper migrations
  • Use proper connection pooling
  • Implement proper transactions
  • Use proper query optimization
  • Handle database errors properly

Authentication

  • Implement proper JWT authentication
  • Use proper password hashing
  • Implement proper role-based access
  • Use proper session management
  • Implement proper OAuth2
  • Handle authentication errors properly

Security

  • Implement proper CORS
  • Use proper rate limiting
  • Implement proper input validation
  • Use proper security headers
  • Handle security errors properly
  • Implement proper logging

Performance

  • Use proper caching
  • Implement proper async operations
  • Use proper background tasks
  • Implement proper connection pooling
  • Use proper query optimization
  • Monitor performance metrics

Testing

  • Write proper unit tests
  • Implement proper integration tests
  • Use proper test fixtures
  • Implement proper mocking
  • Test error scenarios
  • Use proper test coverage

Deployment

  • Use proper Docker configuration
  • Implement proper CI/CD
  • Use proper environment variables
  • Implement proper logging
  • Use proper monitoring
  • Handle deployment errors properly

Documentation

  • Use proper docstrings
  • Implement proper API documentation
  • Use proper type hints
  • Keep documentation updated
  • Document error scenarios
  • Use proper versioning

No result recorded yet. Added it? File a Tried-it report so the next person knows how it went in your editor.

Tried it

Reports from people who added this rule to their editor. They roll up into the badges above.

No one has filed a report yet. Try the prompt and be the first.

License: CC0v1 · published Nov 29, 2026

Comments

No comments yet. If you tried this prompt, say how it went.