Python 3.12 FastAPI Best Practices .cursorrules prompt file
About .cursorrules prompt file
What you can build
Task Management API: Develop an API service using FastAPI for creating and managing tasks. Use pydantic for data validation and serialization, fastapi-users for user management, and fastapi-jwt-auth for secure user authentication. The service should handle CRUD operations, implement caching with fastapi-cache, rate limiting with fastapi-limiter, and use fastapi-pagination for listing tasks efficiently.
E-commerce Platform Backend: Build a backend for an e-commerce platform with FastAPI, utilizing sqlalchemy for ORM, pydantic for data validation, and FastAPI-users for managing user accounts and authentication. Implement fastapi-mail for order confirmation emails, cache product data with fastapi-cache, and handle bulk data retrieval with fastapi-pagination.
Blogging Platform: Create a blogging platform backend with FastAPI, supporting user-created blog posts. Use fastapi-users for account management, sqlalchemy for database transactions, and fastapi-jwt-auth for user authentication. Implement email notifications using fastapi-mail and cache frequently accessed posts using fastapi-cache.
Online Course Platform: Design an online course management backend using FastAPI to handle course content and student enrollments. Utilize pydantic for course data validation, fastapi-users for user authentication, and fastapi-jwt-auth for token management. Implement fastapi-mail for email notifications and leverage fastapi-pagination to manage large lists of courses and student enrollments.
Job Board API: Develop an API for a job board application using FastAPI, focusing on job listings and candidate applications. Use fastapi-users for applicant and recruiter accounts, fastapi-jwt-auth for secure authentication, and sqlalchemy for managing job entries. Implement fastapi-mail for application follow-ups and job alerts, and use fastapi-pagination for efficient job listings.
Subscription Service: Build a subscription service backend with FastAPI, supporting user subscriptions to various plans. Utilize fastapi-users for user management, fastapi-jwt-auth for secure login, and fastapi-mail for sending subscription notifications and invoices. Use fastapi-limiter to prevent abuse of subscription changes and fastapi-cache to quickly retrieve subscription data.
Social Networking Site Backend: Create the backend for a social networking site with FastAPI. Use pydantic for validating user and post data, fastapi-users for handling user profiles and relationships, and fastapi-jwt-auth for authentication. Cache popular posts or user data with fastapi-cache and implement fastapi-pagination for search functionalities.
Event Management System: Develop a backend for managing events using FastAPI. Implement user registration and event creation with fastapi-users and fastapi-jwt-auth. Send event invitations and updates using fastapi-mail and manage large numbers of attendees or events with fastapi-pagination. Employ fastapi-cache to optimize event data retrieval.
Recipe Sharing Platform: Create a platform backend for sharing recipes using FastAPI, with pydantic for recipe data validation. Use fastapi-users for managing user accounts and recipe submissions. Leverage fastapi-mail for recipe sharing notifications and fastapi-cache to store popular recipes for quick access. Use fastapi-pagination for browsing recipes.
Fitness Tracking App API: Build an API for a fitness tracking application with FastAPI. Use pydantic for validating workout and nutrition data, fastapi-users for user management, and fastapi-jwt-auth for secure authentication. Implement fastapi-mail for weekly progress summaries and achievements. Use fastapi-pagination to manage large activity logs and fastapi-cache for frequently accessed data.
Benefits
- Comprehensive stack with essential libraries: fastapi-users, jwt-auth, mail, cache, limiter, pagination ensures robust application features.
- Database excellence with alembic for migrations and sqlalchemy for ORM.
- Dependency management streamlined with Poetry for efficient package handling.
Synopsis
Developers building RESTful APIs with FastAPI can create robust, scalable applications benefiting from strict adherence to Python 3.12 and modern libraries for tasks like authentication, caching, and pagination.
Overview of .cursorrules prompt
The .cursorrules file outlines best practices and guidelines for developing Python applications using Python 3.12 along with several frameworks and tools. It specifies the use of frameworks such as pydantic, fastapi, sqlalchemy, and various fastapi extensions for user management, authentication, email sending, caching, rate limiting, and pagination. Dependency management is handled by poetry, and alembic is recommended for managing database migrations. The file also emphasizes coding standards, like using meaningful names, following PEP 8, using docstrings, writing simple code, and employing list comprehensions and try-except blocks. Additional recommendations include using virtual environments, writing unit tests, utilizing type hints, and avoiding global variables to ensure the creation of clean, efficient, and maintainable code.