by Devin Yang
(This article was automatically translated.)

Published - 4 years ago ( Updated - 4 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


python

The python version of the tirm command

Record how to use python's tirm command

python

Simple test python-thread function and parameters

Record, how to use thread to perform functions

python

Execute system commands with python

How do I execute system commands with Python, here is a simple example