Question:
Can I use FastAPI in Domino Data Lab?
Background:
FastAPI is "a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints." It's growing as an alternative to flask.
Answer:
Yes you can. The typical instructions for starting a published app are that you write your application to serve from a host address of 0.0.0.0
on port 8888
and hit the "publish" button on the apps page. Those same instructions apply for FastAPI, here are steps for a quick example:
Using a Py 3.8 Compute Environment in Domino 4.x, specifically Domino Analytics Distribution Py3.8 R4.0 2021Q2 I created a new project, added an app.sh with:
pip install --user "fastapi[all]"
python app.py
Then added a corresponding app.py file with:
from fastapi import FastAPI
import uvicorn
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
if __name__ == "__main__":
uvicorn.run("app:app",host="0.0.0.0",port=8888,reload = True)
After "publish" the "view app" button reveals your "Hello World" message.
Comments
0 comments
Please sign in to leave a comment.