by Devin Yang
(This article was automatically translated.)

Published - 3 years ago ( Updated - 3 years ago )

1. Installation
pip install fastapi uvicorn
2. Sample programs (of course, if possible, create a verticalenv to run.
from typing import Optional

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def read_root():
    return {"Hello": "World"}


@app.get("/items/{item_id}")
def read_item(item_id: int, q: Optional[str] = None):
    return {"item_id": item_id, "q": q}
On the host side, I will put it into the background execution, and use the following command in the bash environment:
nohup uvicorn main:app --reload --host 0.0.0.0 &
If you want to stop I use the following command
killall uvicorn
 To view execution status, use the
tail -f nohup.out
 

Tags: python

Devin Yang

Feel free to ask me, if you don't get it.:)

No Comment

Post your comment

Login is required to leave comments

Similar Stories


linux, python, colab

How to connect to colab from our Server through ssh?

Introduce a bash I wrote to connect to colab vm through ssh. One line of instructions, get colab OpenSSH Server.

python

Macos executes Python and appears certificate verify processing

When I execute python, I get an error note

python

Simple test python-thread function and parameters

Record, how to use thread to perform functions