Deploying FastAPI Projects
With Pydantic-powered validation, modern design, and blazing speed, FastAPI is becoming the standard for next-generation REST APIs. Skyversal instantly deploys your FastAPI projects with the asynchronous (ASGI) Uvicorn server.
What you'll learn in this guide
- ✅ Required dependencies (Uvicorn requirement)
- ✅ FastAPI app object detection logic
- ✅ Environment variables
- ✅ CORS and production settings
1. Required Dependencies (requirements.txt)
FastAPI applications need the uvicorn server to run at high performance (asynchronously) in production. Make sure your dependency file includes these two packages:
2. How Is the FastAPI App Detected?
When Skyversal detects the fastapi package in your dependencies, it automatically starts your project with Uvicorn.
Skyversal searches for the app = FastAPI() object in these files, in order:
-
main.py(Standard FastAPI convention) -
app.py -
api.py
If your application is inside a folder or has a different name (e.g., src/server.py), go to the Skyversal panel and add a new variable under Settings > Environment Variables:
Key: FASTAPI_APP
Value: src.server:app
3. CORS and Environment Variables
If you're building an API with FastAPI, you'll typically communicate with a frontend (React, Vue, etc.). You can securely configure CORS permissions using URLs entered through the Skyversal panel:
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=[FRONTEND_URL],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get('/')
Common Errors (Troubleshooting)
Fix: Uvicorn can't find the app object. Make sure your file is named main.py or app.py, or that you've correctly set the FASTAPI_APP variable.
Fix: Your GitHub repo is missing requirements.txt or it's in the wrong directory.
Fix: If you have uvicorn.run(app, port=8000) at the bottom of your code, you can remove it; Skyversal handles port management automatically via Uvicorn.
You're Ready! 🚀
After adding the required packages, push your code. Skyversal will have your FastAPI project up and running via Uvicorn in seconds.