FastAPI Sample Application
An example of an application that requires a connection to a PostgreSQL database in order to function.
This application is a Todo List written in Python using the asynchronous FastAPI framework, which requires a connection to PostgreSQL for data storage.

Since the Granite cloud platform is designed to run Docker images, this sample application is packaged in a Docker image that is stored in the Github Container Registry.
The source code for this application is completely open and available for viewing on Github.
What This Demo Shows
- How to run FastAPI apps on Granite
- How to connect to a managed PostgreSQL instance
- How to persist and retrieve data through async SQLAlchemy
- How to use environment variables for configuration
- How to containerize and deploy an app using Docker
Step-by-step guide to launching an application on the Granite cloud platform
-
First of all, to launch this application, you need to have an account on the Granite cloud platform and create a project. If you don’t know how to create a new project, you can find detailed instructions here.
-
Before creating an application, you need to have a database. To do this, select the Databases section in the menu and create a new database. You can find step-by-step guide how to create new PostgreSQL database here.
-
If you already have a database, prepare the Connection String, which will be needed later. The Connection String is constructed as follows:
postgresql+asyncpg://<username>:<password>@<host>:<port>/<db-name>Let’s take a closer look at each necessary parameter:
<username>— the username for connecting to the database. This can beadminif you want to use the default credentials, or any other user you have created.<password>— the<username>'spassword. It is generated automatically when creating a database (for the admin user) or when creating a new user.<host>:<port>must refer to the Private endpoint from the Connection details section of the database (click the database in the Databases section to open it).

<db-name>is the name of the database you want to connect to. By default, this isnovpsdb, but you can create any other database on the Databases & Users tab of the database.
Please note that the <username> must have read, write, and create access to the specified database.
- Now we are ready to deploy the FastAPI Sample Application. Go to the Apps section and click the Create app button.

- The new application form opens. In the Source section, switch to Docker image and open the Docker image field. Choose
ghcr.io/novps/fastapi-sample-appfrom the list, or choose Add new repository and enterghcr.io/novps/fastapi-sample-app.

- Leave the Image Tag as
latestand the Credentials empty — the image is public. Click Use this image.

- The form now shows the settings of the resource. The application consists of a single web app, which is selected by default. Pick a size — Extra Small is enough for the sample — and leave the rest unchanged. If necessary, you can change the resource configuration later.

- Scroll down to the Variables section. Remember in step 3 of this guide we collected the Connection String? You need to add it to the application. In the case of FastAPI Sample Application, it doesn’t matter where you specify the environment variable: in the variables shared by every resource of this app or in the variables of the resource itself.
In the Key field, specify DATABASE_URL, and in the Value field, specify your Connection String from step 3.

- Check the summary on the right and click Create app with 1 resource to create the application.

- Once the application has been successfully created, you will be redirected to the application page, where you will see the web resource of the FastAPI Sample Application being deployed.

- When the application is successfully deployed on the Granite cloud platform, the resource shows 1/1 ready. You can now open the FastAPI Sample Application by clicking its address in the Endpoints column.


If you still have questions, continue exploring the Help Center. If you encounter any problems during the process, feel free to contact support or your personal manager if you have paid for the corresponding tariff plan.