FastAPI framework¶
The FastAPI extension streamlines the process of building FastAPI application rocks.
It facilitates the installation of FastAPI application dependencies, including
Uvicorn, inside the rock. Additionally, it transfers your project files to
/app within the rock.
Note
The FastAPI extension is compatible with the bare and ubuntu@24.04
bases.
Project requirements¶
There are 2 requirements to be able to use the fastapi-framework extension:
There must be a
requirements.txtfile in the root of the project withfastapideclared as a dependencyThe project must include a ASGI app in a variable called
appin one of the following files relative to the project root (in order of priority):app.pymain.py__init__.py,app.pyormain.pywithin theapporsrcdirectory or within a directory with the name of the rock as declared in the project file.
parts > fastapi-framework/dependencies: > stage-packages¶
You can use this key to specify any dependencies required for your FastAPI
application. In the following example we use it to specify libpq-dev:
parts:
fastapi-framework/dependencies:
stage-packages:
# list required packages or slices for your FastAPI application below.
- libpq-dev
parts > fastapi-framework/install-app > prime¶
You can use this field to specify the files to be included or excluded from
your rock upon rockcraft pack. Follow the app/<filename> notation. For
example:
parts:
fastapi-framework/install-app:
prime:
- app/.env
- app/app.py
- app/webapp
- app/templates
- app/static
Some files, if they exist, are included by default. These include:
app, src, <rock name>, app.py, migrate, migrate.sh,
migrate.py, static, templates.