FastAPI Recipe ⚡
Modern security automation for FastAPI applications with production/development separation and async-focused optimizations.
Perfect For
- FastAPI REST APIs and web services
- Modern async Python applications using async/await
- Microservices architecture and cloud-native apps
- API-first development with OpenAPI integration
Project Structure
fastapi-app/
├── requirements.txt # Production dependencies
├── requirements-dev.txt # Development dependencies
├── main.py # FastAPI application
├── app/ # Application modules
│ ├── __init__.py
│ ├── models.py
│ ├── routers/
│ └── database.py
└── .github/workflows/
└── fastapi-security.yml # FastAPI security workflow
FastAPI Requirements Structure
# Core FastAPI stack
fastapi>=0.103.0
uvicorn[standard]>=0.23.0
pydantic>=2.3.0
pydantic-settings>=2.0.0
# Database and ORM
sqlalchemy>=2.0.0
alembic>=1.11.0
asyncpg>=0.28.0 # or aiomysql
# Production dependencies
python-multipart>=0.0.6
python-jose[cryptography]>=3.3.0
passlib[bcrypt]>=1.7.4
Complete FastAPI Security Workflow
Complete fastapi-security.yml
This workflow provides optimized security scanning for FastAPI applications with separate prod/dev analysis.
FastAPI-Specific Security Features
This recipe includes FastAPI-optimized security features:
FastAPI Security Enhancements
FastAPI-specific packages automatically scanned: - FastAPI framework and extensions - Async HTTP clients (httpx, aiohttp) - Async database drivers (asyncpg, aiomysql) - ASGI servers (uvicorn, hypercorn) - Async task queues (celery, arq)
Special attention to API security dependencies: - Authentication (python-jose, passlib) - Validation (pydantic, email-validator) - CORS and middleware security - OpenAPI documentation security
Quick Setup Instructions
Step-by-step FastAPI installation
-
Create workflow directory:
-
Download FastAPI workflow:
-
Ensure requirements structure:
FastAPI-Specific Verification
Test Your FastAPI Setup
- Verify both production and development scans work
- Check production vulnerabilities fail the workflow
- Confirm development vulnerabilities are logged but don't fail
- Test manual triggers work correctly
FastAPI-Specific Validations: - ✅ Production dependencies scan successfully - ✅ Development dependencies scan (with tolerance) - ✅ FastAPI-specific packages detected - ✅ API security dependencies validated
What This Recipe Provides
Your FastAPI application will have:
- 🚀 Production-focused security - Critical for API services
- ⚡ Fast parallel scanning - Optimized for CI/CD
- 📱 API-specific validation - FastAPI and async packages
- 🔍 Comprehensive coverage - Production and development deps
- 🛡️ Smart failure logic - Fail on prod, warn on dev vulnerabilities
Ready for More Complex Setups?
Once your FastAPI recipe is working:
- Enterprise Recipe - For multiple environments
- Monorepo Recipe - For multiple FastAPI services
- Django Recipe - If you also have Django services