Hi ๐๐
In this post, I will show you how to Deploy the FastAPI App or API Free On Vercel For free
Step 1
Install Vercel cli
from here
Step 2
Login to Vercel
How to login
Create a project
app--
api.py
main.py
requirements.txt
vercel.json
app.py
from fastapi import FastAPI
app = FastAPI()
@app.get('/')
def home():
return {'msg': 'Welcome in my api'}
main.py
from dotenv import load_dotenv
import os
import uvicorn
load_dotenv()
PORT = int(os.get('PORT', 8000))
HOST = '0.0.0.0'
if __name__ == '__main__':
uvicorn.run('app.api:app', host = HOST, port = PORT, reload = True)
requirements.txt
You can generate requirements.txt using pipreqs
https://pypi.org/project/pipreqs/
vercel.json
{
"builds": [{
"src": "app/api.py",
"use": "@vercel/python",
"config": { "maxLambdaSize": "15mb" }
}],
"routes": [
{
"src": "/(.*)",
"dest": "app/api.py"
}
]
}
Step 3
Go to your project directory and open the cmd or terminal
type
vercel .
You will see things like this
Make the same answers
Vercel CLI 33.3.0
โ๏ธ Your Project was either deleted, transferred to a new Team, or you donโt have access to it anymore.
? Set up and deploy โ~\OneDrive\Desktop\python new videos\How to Deploy FastAPI App or API For Free On Vercelโ? [Y/n] y
? Which scope do you want to deploy to? username
? Link to existing project? [y/N] n
? Whatโs your projectโs name? testapi
? In which directory is your code located? ./
๐ Linked to username/testapi (created .vercel)
๐ Inspect: https://vercel.com/username/testapi/CdFMgqWYpMmxPi7fiPx9jxvbnSNR [2s]
โ
Production: https://testapi-k0lnh2w00-username.vercel.app [2s]
๐ Deployed to production. Run `vercel --prod` to overwrite later (https://vercel.link/2F).
๐ก To change the domain or build command, go to https://vercel.com/username/testapi/settings
Now you can use your API ๐
Now we're done ๐ค
Don't forget to like and follow ๐
Top comments (1)
Error: Unable to find any supported Python versions.?