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.?