avatarShinichi Okada

Summary

The article discusses how to use Deta Micros to deploy a FastAPI website demo for free after Heroku announced plans to eliminate free services.

Abstract

The author of the article had a FastAPI website demo using a Heroku free plan, but after Heroku announced plans to eliminate free services, they looked for alternatives and found Deta, Porter, and Render. They tried Deta Micros and found it suitable for their needs. The article provides a step-by-step guide on how to get started with Deta Micros, including installation, login, creating a new Python project, and updating environment variables. The author also discusses some limitations of Deta, such as the total upload size limit of 250 MB and the inability to use large libraries like Numpy or Scipy.

Opinions

  • Deta Micros is a good alternative to Heroku for deploying a FastAPI website demo for free.
  • Deta Micros has some limitations, such as the total upload size limit of 250 MB and the inability to use large libraries like Numpy or Scipy.
  • Deta Micros provides easy start, cron, custom domain, environment variables, and more.
  • The author recommends updating paths accordingly when moving files from a directory to the root directory.
  • The author suggests that Deta Micros is suitable for a simple demo site or a small app.

From Heroku to Deta to Host Python Project for Free

Heroku announced plans to eliminate free plans and this is what I did

Photo by Prometheus Design on Unsplash

In August 2022, Heroku announced plans to eliminate free services and pushing users to paid plans.

I have a FastAPI website demo using a Heroku free plan. I looked around and found that Deta, Porter and Render offer a free plan. I tried Deta Micro and it works well for my needs. In this article, you will find how to get started with Deta Micros.

Why is Deta Cloud free for ever? We want anyone, at any age from anywhere in the world to experiment and build their ideas without worrying about limits of credit cards.

One of the resources, Deta Micros deploy scalable Node & Python apps. Other resources are Deta Base (Database with a feature-rich API) and Deta Drive (Upload, host and serve images and files with the storage limit of 10GB).

Preparation

Deta uses python 3.7, 3.8, 3.9. When you run deta new command, it will use Python3.9 by default. Since my project uses 3.8, I needed to upgrade my local version to Python to 3.9 to test it.

pyenv install 3.9.13
pyenv global 3.9.13

Getting started

First thing I did was to install deta cli:

curl -fsSL https://get.deta.dev/cli.sh | sh

Next you need to login to Deta from your terminal:

deta login

Create a new Python project.

deta new --python fastapi-webstarter-demo

I copied my repo content to this directory.

Remove app folder

My repo uses an app directory and uvicorn main:app --reload --port 8080 to launch a website. Deta runs Python from the root directory, so I needed to move all files in the app directory to the root directory. This requires to updating paths for some files.

Moving files from app to root directory.
Updating a path

Requirements.txt

Deta installs all dependencies from your requirements.txt. Some packages are not necessary with Deta. For example, uvicorn and dotenv are already provided. Also crontab won’t work in a server-less environment. (Deta Micros provides cron job.)

Environment variables

I use the .env file to store all my environment variables. You can use the following command to update your environment variables:

deta update -e .env

Alias name

Rather than using a default URL, you can add a subdomain.

Creating subdomain.

Source code and dependencies size

Each Micro has to fit in the total upload size of 250 MB including source code, dependencies, and assets. You can’t use Deta with a big library such as Numpy or Scipy, etc.

Conclusion

Deta is a perfect fit for a Python/Node demonstration project. You can’t use more than 250 MB, but it provides easy start, cron, custom domain, environment variables and more.

Since Deta requires you to have a main.py in the root directory, you need to update your paths accordingly when you move files from the directory.

There are some limitations to Deta. It is suitable for a simple demo site or a small app.

References

Get full access to every story on Medium by becoming a member.

https://blog.codewithshin.com/subscribe
Free Hosting
Microserver
Python Hosting
Node Hosting
Fastapi
Recommended from ReadMedium