Don't Wait for PythonAnywhere. Here's How to Deploy FastAPI Project Online
Emily Parker
Product Engineer · Leapcell

FastAPI is a modern Python web framework. Since its creation, it has quickly gained immense popularity within the developer community, thanks to its excellent performance, ease of use, and powerful features. It has even started to replace older frameworks like Flask.
However, deploying FastAPI online isn't as straightforward as it is with older frameworks.
Many people who deploy Python projects use PythonAnywhere because it offers a very simple user interface and has a free tier for small projects.
Unfortunately, PythonAnywhere doesn't support FastAPI. The official explanation is that "the platform only supports WSGI projects, not ASGI projects". You don't need to know what's WSGI and what's ASGI, just that FastAPI can't be deployed there.
Official progress on supporting FastAPI has been very slow. It's still in the testing phase, and only a few people have successfully deployed their projects to the platform.
So, what are the alternatives besides PythonAnywhere? Many people might turn to VPS (Virtual Private Servers), such as AWS EC2 or DigitalOcean.
A VPS acts like a real machine and can therefore support FastAPI's underlying implementation. However, using a VPS for deployment requires you to consider many issues, such as:
- How to configure and install the Python environment so the project can run on the VPS.
- How to configure the network and firewall to prevent your machine from being exposed to the internet and exploited by hackers.
- What other costs, besides the machine rental fee, you need to pay.
Furthermore, a VPS isn't suitable for deploying a small project. As it's an entire machine, the price is usually quite high, and once the machine is enabled, you are charged continuously whether you use it or not.
Is There a Better Option?
Another approach is to use Leapcell.
Leapcell is a web app hosting platform that supports one-click deployment for various languages and frameworks, including FastAPI.
Leapcell's pricing is based on the actual usage of your API. This means that if your deployed project isn't being used, you won't be charged a single penny, unlike with a VPS, which bills you constantly.
Here are the steps to deploy a FastAPI project with Leapcell:
-
Commit your FastAPI project to GitHub, as Leapcell will pull the code from your repository. For detailed instructions, you can refer to GitHub's official documentation.
-
Register on Leapcell. After registering, click "Create Service" on the Leapcell page.
-
Select your FastAPI project. You'll see that the various deployment configurations have been filled out automatically for you.
-
Click Submit at the bottom to deploy. Deployment will be completed quickly, and you'll be returned to the deployment home page. Here, you'll see a domain provided by Leapcell. This is the online address for your project.
Now, you can access your FastAPI project online using this address. The usage is completely consistent with local development and debugging.
For example:
Local: GET http://localhost:3000/users/{userId}
Online deployment: https://xxxxx.leapcell.dev/users/{userId}
Leapcell also includes many other commonly used developer features, such as logs, traffic analytics, and databases. Feel free to explore them!