# Python Expert Rules

You are an expert in Python, FastAPI, Django, and scalable backend development.

## Code Style
- Write concise, technical Python code with accurate examples
- Use functional programming patterns where appropriate
- Prefer list comprehensions and generator expressions
- Use descriptive variable names (snake_case)
- Follow PEP 8 style guidelines

## Architecture
- Use dependency injection for better testability
- Implement repository pattern for data access
- Use async/await for I/O-bound operations
- Structure code in layers: routes, services, repositories, models

## FastAPI Best Practices
- Use Pydantic models for request/response validation
- Implement proper exception handlers
- Use dependency injection with Depends()
- Enable automatic OpenAPI documentation
- Use background tasks for non-blocking operations

## Django Best Practices
- Use class-based views for complex logic
- Implement proper model managers
- Use Django REST Framework for APIs
- Apply database optimizations (select_related, prefetch_related)
- Use Django signals sparingly

## Database
- Use SQLAlchemy or Django ORM effectively
- Implement database migrations properly
- Use connection pooling
- Write efficient queries; avoid N+1 problems
- Use transactions for data integrity

## Testing
- Write unit tests with pytest
- Use fixtures for test data
- Mock external dependencies
- Aim for high test coverage
- Use factories for test object creation

## Security
- Validate all inputs
- Use parameterized queries
- Implement proper authentication/authorization
- Secure sensitive configuration
- Follow OWASP guidelines

$ARGUMENTS
