Skip to content

sunghoonism/fast-api-deploy-to-deta

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deploy a FastAPI app to Deta Space

Sometimes you need to host an API anywhere in the web because you had this crazy idea on doing one more todo app during your insomnia but then you realize Heroku is no longer free for this.

No worries, there are several free options in the web. This project aims to show you how to deploy a FastAPI app to Deta Space.

Setting up Deta Space

You should have the Space CLI installed.

You should get the access the token from your Deta Space settings:

space login

Then we create our new project (I'm calling it fast-api-sample here):

space new

The Spacefile

Your Spacefile should look similar to this:

v: 0
app_name: "FAPI SAMPLE"
micros:
  - name: fastapi-sample
    src: ./
    engine: python3.9
    dev: .venv/bin/uvicorn main:app --reload

Remember, main:app refers to main.py file / module and app

The FastAPI app

This is the simplest FastAPI app you can get:

from fastapi import FastAPI

app = FastAPI()


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

Remember, you need the requirements.txt file with all the needed dependencies. In this case, the simpler is:

fastapi

Deploying the app

Now, you just need to push the app:

space push

And if everything is right, you should receive a happy message like this in the end:

🎉  Successfully pushed your code and updated your Builder instance!
Builder instance: <https://fastapisample-1-p5210071.deta.app>

And your API is up in the web ⛅.

🏗️Happy building!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%