Overview
FastrAPI is designed as a drop-in replacement for FastAPI, which means migration is straightforward for most applications. In many cases, you only need to change your import statement.FastrAPI maintains API compatibility with FastAPI’s core features, including decorators, Pydantic models, dependency injection, and middleware.
Basic migration
The simplest migration involves just updating your import statement.Update the server
Replace your ASGI server (Uvicorn/Gunicorn) with FastrAPI’s built-in server:Then simply run:
Side-by-side comparison
Before (FastAPI)
main.py
After (FastrAPI)
main.py
Feature compatibility
- Supported features
- Features in development
The following FastAPI features are fully supported in FastrAPI:
- HTTP methods: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS
- Pydantic models: Request and response validation
- Path parameters:
/users/{user_id} - Query parameters:
/items?skip=0&limit=10 - Request bodies: JSON, form data, multipart
- Response models: Type hints and Pydantic models
- Dependency injection: Function dependencies
- Middleware: CORS, GZip, TrustedHost, Session
- WebSockets: Full async WebSocket support
- OpenAPI: Automatic schema generation
- Type hints: Full Python type annotation support
Common migration scenarios
Middleware migration
Middleware syntax is nearly identical between FastAPI and FastrAPI.Response types migration
WebSocket migration
Handling unsupported features
If your application uses features not yet supported by FastrAPI:APIRouter and include_router
APIRouter and include_router
Status: Not yet implementedWorkaround: Consolidate routes into a single app for now. You can organize routes in separate files and import them:
routes/users.py
main.py
Startup and shutdown events
Startup and shutdown events
Status: In developmentWorkaround: Initialize resources before calling
app.serve():Static files and mounting
Static files and mounting
Status: Not yet implementedWorkaround: Use a reverse proxy (nginx) to serve static files, or keep a small FastAPI instance just for static files alongside your FastrAPI application.
Custom exception handlers
Custom exception handlers
Status: Not yet implementedWorkaround: Handle exceptions within your route handlers:
Performance comparison
After migration, you should see significant performance improvements:| Metric | FastAPI + Gunicorn | FastrAPI | Improvement |
|---|---|---|---|
| Avg Latency | 21.08 ms | 0.59 ms | 35.7x faster |
| Requests/sec | 937 | 31,360 | 33.5x more |
| P95 Latency | 38.47 ms | 2.39 ms | 16.1x faster |
| P99 Latency | 93.42 ms | 11.12 ms | 8.4x faster |
Migration checklist
Use this checklist to ensure a smooth migration:- Update imports from
fastapitofastrapi - Change
FastAPI()toFastrAPI() - Replace ASGI server (Uvicorn) with
app.serve() - Update middleware imports (e.g.,
fastrapi.middleware) - Update response type imports (e.g.,
fastrapi.responses) - Test all endpoints for correctness
- Verify Pydantic model validation
- Test WebSocket connections (if used)
- Check middleware functionality
- Update deployment scripts
- Run performance benchmarks
- Update documentation
- Plan workarounds for unsupported features
Deployment changes
Before (FastAPI with Uvicorn)
After (FastrAPI)
main.py
FastrAPI’s built-in server is powered by Rust’s Tokio runtime and handles concurrency efficiently without needing multiple workers.
Gradual migration strategy
For large applications, consider a gradual migration:Getting help
If you encounter issues during migration:- Check the GitHub issues for known problems
- Review the examples directory for working code
- Open a new issue with details about your migration challenge
- Join the community discussions
Next steps
Quickstart
Learn FastrAPI features in depth
Advanced features
Explore advanced FastrAPI capabilities
Performance tuning
Optimize your FastrAPI application
GitHub
Contribute to FastrAPI