Skip to main content

Deploy FastAPI server

Deploying a FastAPI server on Replit is quick and easy. Replit offers a modern web framework for building high-performance APIs with Python 3.7+.

Follow the steps below to deploy your FastAPI server on Replit:

Step 1: Fork the FastAPI template by using the button + Use Template on Replit. In the Repl, you’ll see the code that is used for deployment.

    from typing import Union

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def read_root():
return {"Hello": "World"}

@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}

Step 2: In the workspace header, select Deploy button and from the available types of deployments, choose Autoscale. Then, select the Set up your deployment button.

Step 3: Use the following configuration during your setup:

  • Machine configuration: You can keep the default values. The default machine configuration is a 1vCPU and 2 GiB RAM.
  • Select the Approve and configure build settings button to continue with the build settings.

Step 4: In the tab that opens, the Type is defaulted to the selected deployment type. Here it is Autoscale. You can select Manage to change the type of deployment:

  • Primary domains: Choose a domain name of your choice for your app.
  • Build command: This is an optional command. You can leave it blank.
  • Run command: Enter the command uvicorn main:app --host 0.0.0.0 into the Run command field.
  • Select the Deploy button to start the deployment process.

After a few minutes, your app will be live!

In the future, whenever you want to change your live deployment, you can change the deployment options by selecting the Manage button and then using the Approve and update button to update the changes. You can also use the Redeploy button in the workspace header to deploy your application again.