Skip to main content

Introduction

FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.8+ based on standard Python type hints.

Prerequisites

  • a UNIX-like system (see WSL if you are using Windows), in order to use the Valyent CLI
  • a Valyent account, with a registered payment method (you can sign up here)
  • Python3 and installed on your machine

Installing the CLI

You can inspect the installation script here and the GitHub repository.

Authenticating

Initializing the project

In the first place, we are going to install FastAPI dependencies. You can refer to the official documentation for more information.
Then, we can scaffold a new FastAPI project :
Make sure to create a requirements.txt file, in order to install the dependencies in the Docker image :
In the main.py file, we can add the following code :
Now, we can initialize the valyent.toml configuration file, that allows to link the local codebase, to a Valyent application :
This command will ask you to select/create a project and an associated application.

Adding the Dockerfile

Let’s add a Dockerfile so that Valyent can build a Docker image for your application.
We can fill it with the following Dockerfile (coming from here) :

Deploy the project

To expose the application’s port, we need to set up a gateway (in this case, the port 80):
Then, we can deploy the application :
Then, you can type the following:
to test your FastAPI application in your browser.