---
title: "Deploy a FastAPI App"
description: "Learn how to deploy a FastAPI app to Railway with this step-by-step guide. It covers quick setup, one-click deploys, Dockerfile and other deployment strategies."
date: 2026-01-30T00:00:00.000Z
updated: 2026-10-29T11:14:06.951Z
topics: ["Frameworks"]
tags: ["Deployment", "Fastapi", "Python", "Backend"]
url: https://railway.com/guides/fastapi
---

# Deploy a FastAPI App

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

This guide covers how to deploy a FastAPI app on Railway in four ways:

1. [One-click deploy from a template](#one-click-deploy-from-a-template).
2. [From a GitHub repository](#deploy-from-a-github-repo).
3. [Using the CLI](#deploy-from-the-cli).
4. [Using a Dockerfile](#use-a-dockerfile).

## One-click deploy from a template

[![Deploy on Railway](https://cms.railway.com/media/aeo-6ec9624cf8f8a7408f19e40a27a1e6020de459a42ac3fe1c4a016cb01cd1aa9b.png)](https://railway.com/deploy/-NvLj4)

It is highly recommended that [you eject from the template after deployment](https://docs.railway.com/templates/deploy#eject-from-template-repository) to create a copy of the repo on your GitHub account.

**Note:** You can also choose from a <a href="https://railway.com/templates?q=fastapi" target="_blank">variety of FastAPI app templates</a> created by the community.

## Deploy from a GitHub repo

To deploy a FastAPI app on Railway directly from GitHub, follow the steps below:

1. Fork the basic <a href="https://github.com/railwayapp-templates/fastapi" target="_blank">FastAPI GitHub repo</a>.
   - If you already have a GitHub repo you want to deploy, you can skip this step.
2. Create a <a href="https://railway.com/new" target="_blank">New Project.</a>
3. Click **Deploy from GitHub repo**.
4. Select the `fastapi` or your own GitHub repo.
   - Railway requires a valid GitHub account to be linked. If your Railway account isn't associated with one, you will be prompted to link it.
5. Click **Deploy Now**.

Once the deployment is successful, a Railway [service](https://docs.railway.com/services) will be created for you. By default, this service will not be publicly accessible.

To set up a publicly accessible URL for the service, navigate to the **Networking** section in the [Settings](https://docs.railway.com/overview/the-basics#service-settings) tab of your new service and click on [Generate Domain](https://docs.railway.com/networking/public-networking#railway-provided-domain).

![screenshot of the deployed fastapi service showing a hello world API response on a browser](<https://cms.railway.com/media/aeo-9daf789a1e97d8ce8e73e018b14020c8896fb6c9098cbf62a889aaef0f80cb50.avif>)

The FastAPI app is run via a <a href="https://hypercorn.readthedocs.io/en/latest/" target="_blank">Hypercorn server</a> as defined by the `startCommand` in the <a href="https://github.com/railwayapp-templates/fastapi/blob/main/railway.json" target="_blank">railway.json</a> file in the GitHub repository.

Railway makes it easy to define deployment configurations for your services directly in your project using a <a href="https://docs.railway.com/guides/config-as-code" target="_blank">railway.toml or railway.json file</a>, alongside your code.

## Deploy from the CLI

1. <a href="https://docs.railway.com/guides/cli#installing-the-cli" target="_blank">Install</a> and <a href="https://docs.railway.com/guides/cli#authenticating-with-the-cli" target="_blank">authenticate with the CLI.</a>
2. Clone the forked <a href="https://github.com/railwayapp-templates/fastapi" target="_blank">fastapi GitHub repo</a> and `cd` into the directory.
   - You can skip this step if you already have an app directory or repo on your machine that you want to deploy.
3. Run `railway init` within the app directory to create a new project.
4. Run `railway up` to deploy.
   - The CLI will now scan, compress and upload your fastapi app files to Railway's backend for deployment.

## Use a Dockerfile

**Note:** If you already have an app directory or repo on your machine that you want to deploy, you can skip the first two steps.

1. Clone the forked `fastapi` repo and `cd` into the directory.
2. Delete the `railway.json` file.
3. Create a `Dockerfile` in the `fastapi` or app's root directory.
4. Add the content below to the `Dockerfile`:

   ```bash
   # Use the Python 3 alpine official image
   # https://hub.docker.com/_/python
   FROM python:3-alpine

   # Create and change to the app directory.
   WORKDIR /app

   # Copy local code to the container image.
   COPY . .

   # Install project dependencies
   RUN pip install --no-cache-dir -r requirements.txt

   # Run the web service on container startup.
   CMD ["hypercorn", "main:app", "--bind", "::"]
   ```

5. Either deploy via the CLI or from GitHub.

Railway automatically detects the `Dockerfile`, [and uses it to build and deploy the app.](https://docs.railway.com/builds/dockerfiles)

**Note:** Railway supports also <a href="https://docs.railway.com/guides/services#deploying-a-public-docker-image" target="_blank">deployment from public and private Docker images</a>.

## Next steps

Explore these resources to learn how you can maximize your experience with Railway:

- [Add a Database Service](https://docs.railway.com/databases/build-a-database-service)
- [Monitor your app](https://docs.railway.com/observability)
- [Running a Cron Job](https://docs.railway.com/cron-jobs)