FastAPI
FastAPI is a modern, async Python framework that makes it easy to build performant APIs with automatic OpenAPI docs. Use this component when you want Diploi to run uvicorn builds and handle deploys so you can focus on type-safe endpoints and business logic.
Add to your project
Section titled “Add to your project”Paste this entry into the components list in diploi.yaml to add FastAPI to your project.
components: - name: FastAPI identifier: fastapi package: https://github.com/diploi/component-fastapi#v0.136.1FastAPI reference
Section titled “FastAPI reference”Readme
Section titled “Readme”Operation
Section titled “Operation”Getting started
Section titled “Getting started”- In the Dashboard, click Create Project +
- Under Pick Components, choose FastAPI. Here you can also add a frontend framework to create a monorepo app, eg, FastAPI for backend and React+Vite for frontend
- In Pick Add-ons, you can add one or multiple databases to your app
- Choose Create Repository to generate a new GitHub repo
- Finally, click Launch Stack
Link to the full guide https://diploi.com/blog/hosting_fastapi_apps
Python version
Section titled “Python version”The default Python version is 3.12. You can change it in two ways:
PYTHON_VERSIONenvironment variable - set this indiploi.yamlas a static ENV under your component’s environment variables. This controls the version used by both the development and production environments..python-versionfile - add a.python-versionfile to your component’s folder containing just the version number (e.g.3.11). This is the standard convention used byuvand other Python tools, and is a good choice if you want the version pinned in your repository.
If both are set, the .python-version file takes precedence.
Development
Section titled “Development”The development server is started with:
uv run --with uvicorn uvicorn src.main:app --host 0.0.0.0 --port 8000 --reload --reload-dir src --reload-dir .venv/libThis can be changed with the containerCommands.developmentStart field in diploi.yaml.
Production
Section titled “Production”Builds a production-ready image. During the build, dependencies are installed with uv sync or uv pip install. When the container starts, it runs:
uv run --with uvicorn uvicorn src.main:app --host 0.0.0.0 --port 8000 --proxy-headersThis can be changed with the containerCommands.productionStart field in diploi.yaml.