AI Prompts Library

Curated collection of expert prompts for coding, writing, marketing, image generation, and more

Have a great prompt? Submit it to the library →

Coding

Python FastAPI Backend Generator

Optimized for: general • TEXT
You are a senior backend engineer specializing in Python FastAPI applications. Generate a complete, production-ready API module based on the requirements below.

**Module Requirements:**
- Resource name: [RESOURCE_NAME, e.g., 'users', 'products', 'orders']
- Database: [PostgreSQL/MongoDB/SQLite]
- ORM: [SQLAlchemy/Tortoise-ORM/Motor]
- Authentication: [JWT/OAuth2/API Key/None]
- Description: [WHAT_THIS_MODULE_DOES]

**Generate the following files:**

1. **models.py** - SQLAlchemy/Pydantic models:
   - Database model with proper column types, indexes, and constraints
   - Created_at, updated_at timestamps with timezone awareness
   - Soft delete support (is_deleted flag)
   - Relationship definitions

2. **schemas.py** - Pydantic v2 schemas:
   - CreateSchema (input validation for POST)
   - UpdateSchema (partial updates for PATCH, all fields Optional)
   - ResponseSchema (API output, excludes sensitive fields)
   - ListResponseSchema (paginated list with metadata)
   - Use Field() validators with examples in json_schema_extra

3. **router.py** - FastAPI router:
   - GET / - List with pagination, sorting, filtering
   - GET /{id} - Single resource with 404 handling
   - POST / - Create with 201 response and Location header
   - PATCH /{id} - Partial update
   - DELETE /{id} - Soft delete with 204 response
   - Include proper response_model, status_code, summary, description
   - Dependency injection for auth, database session

4. **service.py** - Business logic layer:
   - CRUD operations separated from route handlers
   - Transaction management
   - Custom exception classes
   - Event hooks (pre_create, post_create, etc.)

5. **tests/test_[resource].py** - Pytest tests:
   - Test each endpoint with valid and invalid data
   - Test authentication and authorization
   - Test edge cases (duplicate, not found, validation errors)
   - Use pytest fixtures and httpx AsyncClient

All code must include type hints, docstrings, and follow PEP 8.

Rapid scaffolding of production-quality FastAPI backend modules

Coding

Python Debugging Expert Assistant

Optimized for: gpt-4o • TEXT
You are an expert Python debugger with deep knowledge of common pitfalls, edge cases, and debugging strategies.

**Error/Issue:**
[DESCRIBE THE PROBLEM OR PASTE ERROR MESSAGE]

**Code:**
```python
[PASTE YOUR PYTHON CODE HERE]
```

**Environment:**
- Python version: [VERSION]
- Operating System: [OS]
- Dependencies: [LIST KEY PACKAGES]

**Expected Behavior:**
[WHAT SHOULD HAPPEN]

**Actual Behavior:**
[WHAT ACTUALLY HAPPENS]

**Please provide:**

1. **Root Cause Analysis**
   - Identify the exact source of the problem
   - Explain why it occurs
   - Note any misunderstandings of Python concepts

2. **Immediate Fix**
   - Provide corrected code with inline comments
   - Highlight the changes

3. **Best Practices**
   - Suggest improvements beyond just fixing the bug
   - Recommend better patterns or approaches
   - Add error handling if missing

4. **Prevention**
   - How to avoid this issue in the future
   - Testing approach for this scenario
   - Relevant Python idioms or patterns

5. **Additional Context**
   - Related Python gotchas
   - Performance considerations
   - Alternative implementations

Debug Python code, learn from errors, improve code quality, understand Python idioms

Want Custom Prompts?

Get personalized AI prompts tailored to your specific needs and workflow.

Contact Us