DEV Community

Cover image for FastAPI Deployment on Deta
cptMoh
cptMoh

Posted on

FastAPI Deployment on Deta

We started using FastAPI, the Python web framework that's fast gaining popularity recently in our organisation. Which, by the way, I recommend to everyone building APIs with python because of how fast and easy it is to setup and get going. Fast API also boasts of speeds that are on par with NodeJs and GoLang because of its async nature.

Anyways, this led me to researching different ways of deploying FastAPI to a staging server for testing purposes before moving to production. Along the way, I bumped into Deta, a rather new and interesting platform as a service(PAAS), just like Heroku(which i have used a few times).

What's even more interesting about Deta is the fact that I found it on FastAPIs' website. Well, that has to count for something, right? I mean, if FastAPI, which is this mean beast of a python web framework is pushing for Deta, then it too must be just as good, right? Well, dig in and follow me as we go through my journey of discovery.

First of all, like i've told you before, FastAPI is really super fast to setup and get your api running in a few minutes, so, it makes sense that it will push for a platform that is just as easy and fast to make your deployments, yeah...? You got that right!

Deta deployments are insanely easy and quick with FastAPI. you can get your app up and running on their micros in under five minutes! I mean if that's not impressive, then I don't know what is. just a few clicks here and there and voila.

  • Before you do anything else, you need to create a free account with Deta

  • Done that? good. the very next thing you need to do is to download the Deta CLI.
    You can do that like this on a MAC/Linus OS:

curl -fsSL https://get.deta.dev/cli.sh | sh 
Enter fullscreen mode Exit fullscreen mode


Or like this on Windows:

iwr https://get.deta.dev/cli.ps1 -useb | iex
Enter fullscreen mode Exit fullscreen mode
  • Easy-peasy. now you need to login to your through your cli
deta login
Enter fullscreen mode Exit fullscreen mode
  • Now, before this next step, you need to make your your 'app' is defined in a 'main.py' file on the directory you are working from. You also need to make sure your 'requirements.txt' file is located in that same directory. If you have all of that set, then go ahead and do this:
deta new
Enter fullscreen mode Exit fullscreen mode

It should take about a minute, and then you'll get a response that should look like this.

deta new

Successfully created a new micro

πŸ’¬ Notice the "endpoint" πŸ”

{
    "name": "fastapideta",
    "runtime": "python3.7",
    "endpoint": "https://qltnci.deta.dev",
    "visor": "enabled",
    "http_auth": "enabled"
}

Adding dependencies...


β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ 100%


Successfully installed fastapi-0.61.1 pydantic-1.7.2 starlette-0.13.6

Enter fullscreen mode Exit fullscreen mode

That's it, super easy and fast. you can access your app when you go to that endpoint.

I know what you must be thinking, lol. If deploying your fastAPI app on Deta was so easy, fast, and free, then why isn't everyone doing it, right?

Not so fast, smarty pants. The reason why so many people are not doing it is because there's a catch, or a few catches, actually.

  1. With the exception of mysqlite3 and their native Deta Base, Deta micros don't work well with any other database. so hard luck if you're like me and you like using MongoDB because Deta totally does not support it. At least for now.
    I suspect if you're testing your app on a staging server then you'd want to test your app as it would function on production right? well if it's not too much of a hassle switching between databases then it's not really a big deal.
    Deta Base is really easy to set up and get going as well. i guess this is starting to become a trend for anything linked with FastAPI

  2. For some reason, background tasks also don't work well on Deta. so good luck trying to test out your email sending functionality as a background task, lol.

  3. Deta only supports micro web frameworks(think FastAPI and Flask) and no Django or any other big web framework.

  4. Web sockets also do not work well on Deta.

If all of these are not an issue, then you should really check out Deta for deploying your FastAPI applications. They're meant to go hand in hand. And we hope Deta gets even better in the future. we'd love to see support for more Relational and non relational databases.

PS. I'd really love to hear about your thoughts on deta and FastAPI. Do you know of other ways of deployment you'd care to share? please leave a comment below.

Top comments (0)