Deploy FastAPI on Deta

    The current page still doesn’t have a translation for this language.

    But you can help translating it: Contributing.

    In this section you will learn how to easily deploy a FastAPI application on using the free plan. 🎁

    It will take you about 10 minutes.

    Info

    Deta is a FastAPI sponsor. 🎉

    • Create a directory for your app, for example, and enter into it.
    • Create a main.py file with:

    Now, in the same directory create a file requirements.txt with:

    Tip

    You don’t need to install Uvicorn to deploy on Deta, although you would probably want to install it locally to test your app.

    You will now have one directory ./fastapideta/ with two files:

    Create a free Deta account

    Now create a free account on Deta, you just need an email and password.

    You don’t even need a credit card.

    Install the CLI

    Once you have your account, install the Deta CLI:

    Windows PowerShell

    Deploy FastAPI on Deta - 图2

    After installing it, open a new terminal so that the installed CLI is detected.

    Tip

    If you have problems installing the CLI, check the official Deta docs.

    Now login to Deta from the CLI with:

    Deploy FastAPI on Deta - 图4

    This will open a web browser and authenticate automatically.

    Deploy with Deta

    Next, deploy your application with the Deta CLI:

    You will see a JSON message similar to:

    Tip

    Your deployment will have a different URL.

    Check it

    Now open your browser in your endpoint URL. In the example above it was https://qltnci.deta.dev, but yours will be different.

    You will see the JSON response from your FastAPI app:

    And now go to the /docs for your API, in the example above it would be .

    It will show your docs like:

    Deploy FastAPI on Deta - 图6

    By default, Deta will handle authentication using cookies for your account.

    Now you can share that URL with anyone and they will be able to access your API. 🚀

    HTTPS

    Congrats! You deployed your FastAPI app to Deta! 🎉 🍰

    Also, notice that Deta correctly handles HTTPS for you, so you don’t have to take care of that and can be sure that your clients will have a secure encrypted connection. ✅ 🔒

    Check the Visor

    From your docs UI (they will be in a URL like https://qltnci.deta.dev/docs) send a request to your path operation /items/{item_id}.

    For example with ID 5.

    Now go to .

    You will see there’s a section to the left called “Micros” with each of your apps.

    You will see a tab with “Details”, and also a tab “Visor”, go to the tab “Visor”.

    In there you can inspect the recent requests sent to your app.

    You can also edit them and re-play them.

    Deploy FastAPI on Deta - 图8

    At some point, you will probably want to store some data for your app in a way that persists through time. For that you can use , it also has a generous free tier.

    You can also read more in the Deta Docs.

    Deployment Concepts

    Coming back to the concepts we discussed in Deployments Concepts, here’s how each of them would be handled with Deta:

    • HTTPS: Handled by Deta, they will give you a subdomain and handle HTTPS automatically.
    • Running on startup: Handled by Deta, as part of their service.
    • Restarts: Handled by Deta, as part of their service.
    • Replication: Handled by Deta, as part of their service.
    • Previous steps before starting: Not directly supported, you could make it work with their Cron system or additional scripts.

    Note

    Deta is designed to make it easy (and free) to deploy simple applications quickly.

    You can read more details in the to see if it’s the right choice for you.