美文网首页
FastAPI 一(安装)

FastAPI 一(安装)

作者: 地雷 | 来源:发表于2020-01-17 09:16 被阅读0次

需要安装的包 与 一个小案例

链接三连
FastAPI
https://fastapi.tiangolo.com/
Uvicorn
http://www.uvicorn.org/
Starlette
https://www.starlette.io/
Pydantic
https://pydantic-docs.helpmanual.io/
三连有四个不是常识吗

前言

FastAPI是一种现代,快速(高性能)的Web框架,用于基于标准Python类型提示使用Python 3.6+构建API。(来自谷歌翻译)

FastAPI基于以下
使用Uvicorn服务器 ASGI规范(ASGI是异步服务器网关接口 是WSGI的精神继承者,在具有异步功能的Python Web服务器,框架和应用程序之间提供标准接口。)
Starlette是一种轻量级的ASGI框架/工具包,是构建高性能异步服务的理想选择。
Pydantic用于验证数据

安装

pip install -i https://mirrors.aliyun.com/pypi/simple/ fastapi
安装fastapi的时候可以看到安装了哪些包
Installing collected packages: dataclasses, pydantic, starlette, fastapi
pip install -i https://mirrors.aliyun.com/pypi/simple/ uvicorn

First Steps

""" 第一个例子 文件名main.py"""
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def root():
   return {"message": "Hello World"}

运行
uvicorn main:app --reload

访问
http://127.0.0.1:8000/
http://127.0.0.1:8000/docs
http://127.0.0.1:8000/redoc
可以很方便的测试接口

相关文章

网友评论

      本文标题:FastAPI 一(安装)

      本文链接:https://www.haomeiwen.com/subject/nnvnoctx.html