deploymentfastapipythonbackend
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:
It is highly recommended that you eject from the template after deployment to create a copy of the repo on your GitHub account.
Note: You can also choose from a variety of FastAPI app templates created by the community.
To deploy a FastAPI app on Railway directly from GitHub, follow the steps below:
fastapi or your own GitHub repo.
Once the deployment is successful, a Railway service 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 tab of your new service and click on Generate Domain.
The FastAPI app is run via a Hypercorn server as defined by the startCommand in the railway.json file in the GitHub repository.
Railway makes it easy to define deployment configurations for your services directly in your project using a railway.toml or railway.json file, alongside your code.
cd into the directory.
railway init within the app directory to create a new project.railway up to deploy.
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.
Clone the forked fastapi repo and cd into the directory.
Delete the railway.json file.
Create a Dockerfile in the fastapi or app's root directory.
Add the content below to the Dockerfile:
Either deploy via the CLI or from GitHub.
Railway automatically detects the Dockerfile, and uses it to build and deploy the app.
Note: Railway supports also deployment from public and private Docker images.
Explore these resources to learn how you can maximize your experience with Railway: