├── .gitignore ├── README.md ├── main.py ├── requirements.txt ├── static └── favicon.ico └── vercel.json /.gitignore: -------------------------------------------------------------------------------- 1 | .vercel 2 | *.log 3 | *.pyc 4 | __pycache__ 5 | 6 | # Environments 7 | .env 8 | .venv 9 | env/ 10 | venv/ 11 | ENV/ 12 | env.bak/ 13 | venv.bak/ -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Deploy FastAPI backends on vercel 2 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from time import time 2 | from fastapi import FastAPI, __version__ 3 | from fastapi.staticfiles import StaticFiles 4 | from fastapi.responses import HTMLResponse 5 | 6 | app = FastAPI() 7 | app.mount("/static", StaticFiles(directory="static"), name="static") 8 | 9 | html = f""" 10 | 11 | 12 | 13 | FastAPI on Vercel 14 | 15 | 16 | 17 |
18 |

Hello from FastAPI@{__version__}

19 | 23 |

Powered by Vercel

24 |
25 | 26 | 27 | """ 28 | 29 | @app.get("/") 30 | async def root(): 31 | return HTMLResponse(html) 32 | 33 | @app.get('/ping') 34 | async def hello(): 35 | return {'res': 'pong', 'version': __version__, "time": time()} -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mabdullahadeel/vercel-fastapi-deployment/ecf88c986c1b6175bfb4eedc2e5680b3b9327d67/requirements.txt -------------------------------------------------------------------------------- /static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mabdullahadeel/vercel-fastapi-deployment/ecf88c986c1b6175bfb4eedc2e5680b3b9327d67/static/favicon.ico -------------------------------------------------------------------------------- /vercel.json: -------------------------------------------------------------------------------- 1 | { 2 | "builds": [ 3 | { 4 | "src": "main.py", 5 | "use": "@vercel/python" 6 | } 7 | ], 8 | "routes": [ 9 | { 10 | "src": "/(.*)", 11 | "dest": "main.py" 12 | } 13 | ] 14 | } 15 | --------------------------------------------------------------------------------