Python Deployment
Deploy Genkit Python applications using Flask, FastAPI, or the built-in flow server. Works with any ASGI/WSGI server and cloud platform.Overview
Genkit Python supports:- Flask integration - Simple web framework
- FastAPI integration - Modern async framework
- Built-in flow server - Zero-config ASGI server
- Any ASGI server - Uvicorn, Gunicorn, Hypercorn
Installation
Flask Deployment
1. Create Flask App
main.py
2. Run Locally
3. Flask with Context Provider
4. Deploy Flask to Production
FastAPI Deployment
1. Create FastAPI App
main.py
2. Run FastAPI
3. Deploy FastAPI to Production
Built-in Flow Server
Use Genkit’s built-in ASGI server to expose all flows automatically:main.py
POST /joke_flowPOST /summarize_flow
With Authentication
Authorization: Bearer your-secret-key header.
Dockerfile
Flask Dockerfile
Dockerfile
FastAPI Dockerfile
Dockerfile
Deployment Platforms
Google Cloud Run
Fly.io
fly.toml
Heroku
Procfile
Railway
AWS Lambda (with Mangum)
lambda_handler.py
Production Best Practices
1. Use Environment Variables
2. Error Handling
3. Request Validation
4. Rate Limiting
5. Health Checks
6. Logging
Monitoring
Google Cloud Telemetry
Structured Logging
Complete Examples
See full Python examples in the repository:Troubleshooting
Import Errors
Problem:ModuleNotFoundError: No module named 'genkit'
Solution: Install dependencies:
Port Already in Use
Problem:Address already in use
Solution: Change port or kill process:
Streaming Not Working
Problem: Streaming responses not received. Solution: Ensure proper content-type:Next Steps
Flask Plugin
Full Flask plugin documentation
Cloud Run
Deploy to Google Cloud Run