<p align="center">
<a href="https://fastapi.tiangolo.com"><img src="https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png" alt="FastAPI"></a>
</p>
<p align="center">
<em>FastAPI framework, high performance, easy to learn, fast to code, ready for production</em>
</p>
<p align="center">
<a href="https://travis-ci.org/tiangolo/fastapi" target="_blank">
<img src="https://travis-ci.org/tiangolo/fastapi.svg?branch=master" alt="Build Status">
</a>
<a href="https://codecov.io/gh/tiangolo/fastapi" target="_blank">
<img src="https://codecov.io/gh/tiangolo/fastapi/branch/master/graph/badge.svg" alt="Coverage">
</a>
<a href="https://pypi.org/project/fastapi" target="_blank">
<img src="https://badge.fury.io/py/fastapi.svg" alt="Package version">
</a>
<a href="https://gitter.im/tiangolo/fastapi?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge" target="_blank">
<img src="https://badges.gitter.im/tiangolo/fastapi.svg" alt="Join the chat at https://gitter.im/tiangolo/fastapi">
</a>
</p>
---
**Documentation**: <a href="https://fastapi.tiangolo.com" target="_blank">https://fastapi.tiangolo.com</a>
**Source Code**: <a href="https://github.com/tiangolo/fastapi" target="_blank">https://github.com/tiangolo/fastapi</a>
---
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints.
The key features are:
* **Fast**: Very high performance, on par with **NodeJS** and **Go** (thanks to Starlette and Pydantic). [One of the fastest Python frameworks available](#performance).
* **Fast to code**: Increase the speed to develop features by about 200% to 300% *.
* **Fewer bugs**: Reduce about 40% of human (developer) induced errors. *
* **Intuitive**: Great editor support. <abbr title="also known as auto-complete, autocompletion, IntelliSense">Completion</abbr> everywhere. Less time debugging.
* **Easy**: Designed to be easy to use and learn. Less time reading docs.
* **Short**: Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs.
* **Robust**: Get production-ready code. With automatic interactive documentation.
* **Standards-based**: Based on (and fully compatible with) the open standards for APIs: <a href="https://github.com/OAI/OpenAPI-Specification" target="_blank">OpenAPI</a> (previously known as Swagger) and <a href="http://json-schema.org/" target="_blank">JSON Schema</a>.
<small>* estimation based on tests on an internal development team, building production applications.</small>
## Requirements
Python 3.6+
FastAPI stands on the shoulders of giants:
* <a href="https://www.starlette.io/" target="_blank">Starlette</a> for the web parts.
* <a href="https://pydantic-docs.helpmanual.io/" target="_blank">Pydantic</a> for the data parts.
## Installation
```bash
$ pip install fastapi
```
You will also need an ASGI server, for production such as <a href="http://www.uvicorn.org" target="_blank">uvicorn</a>.
```bash
$ pip install uvicorn
```
## Example
### Create it
* Create a file `main.py` with:
```Python
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: str = None):
return {"item_id": item_id, "q": q}
```
<details markdown="1">
<summary>Or use <code>async def</code>...</summary>
If your code uses `async` / `await`, use `async def`:
```Python hl_lines="7 12"
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
async def read_item(item_id: int, q: str = None):
return {"item_id": item_id, "q": q}
```
**Note**:
If you don't know, check the _"In a hurry?"_ section about <a href="https://fastapi.tiangolo.com/async/#in-a-hurry" target="_blank">`async` and `await` in the docs</a>.
</details>
### Run it
Run the server with:
```bash
uvicorn main:app --reload
```
<details markdown="1">
<summary>About the command <code>uvicorn main:app --reload</code>...</summary>
The command `uvicorn main:app` refers to:
* `main`: the file `main.py` (the Python "module").
* `app`: the object created inside of `main.py` with the line `app = FastAPI()`.
* `--reload`: make the server restart after code changes. Only do this for development.
</details>
### Check it
Open your browser at <a href="http://127.0.0.1:8000/items/5?q=somequery" target="_blank">http://127.0.0.1:8000/items/5?q=somequery</a>.
You will see the JSON response as:
```JSON
{"item_id": 5, "q": "somequery"}
```
You already created an API that:
* Receives HTTP requests in the _paths_ `/` and `/items/{item_id}`.
* Both _paths_ take `GET` <em>operations</em> (also known as HTTP _methods_).
* The _path_ `/items/{item_id}` has a _path parameter_ `item_id` that should be an `int`.
* The _path_ `/items/{item_id}` has an optional `str` _query parameter_ `q`.
### Interactive API docs
Now go to <a href="http://127.0.0.1:8000/docs" target="_blank">http://127.0.0.1:8000/docs</a>.
You will see the automatic interactive API documentation (provided by <a href="https://github.com/swagger-api/swagger-ui" target="_blank">Swagger UI</a>):
![Swagger UI](https://fastapi.tiangolo.com/img/index/index-01-swagger-ui-simple.png)
### Alternative API docs
And now, go to <a href="http://127.0.0.1:8000/redoc" target="_blank">http://127.0.0.1:8000/redoc</a>.
You will see the alternative automatic documentation (provided by <a href="https://github.com/Rebilly/ReDoc" target="_blank">ReDoc</a>):
![ReDoc](https://fastapi.tiangolo.com/img/index/index-02-redoc-simple.png)
## Example upgrade
Now modify the file `main.py` to receive a body from a `PUT` request.
Declare the body using standard Python types, thanks to Pydantic.
```Python hl_lines="2 7 8 9 10 24"
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
price: float
is_offer: bool = None
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: str = None):
return {"item_id": item_id, "q": q}
@app.put("/items/{item_id}")
def create_item(item_id: int, item: Item):
return {"item_name": item.name, "item_id": item_id}
```
The server should reload automatically (because you added `--reload` to the `uvicorn` command above).
### Interactive API docs upgrade
Now go to <a href="http://127.0.0.1:8000/docs" target="_blank">http://127.0.0.1:8000/docs</a>.
* The interactive API documentation will be automatically updated, including the new body:
![Swagger UI](https://fastapi.tiangolo.com/img/index/index-03-swagger-02.png)
* Click on the button "Try it out", it allows you to fill the parameters and directly interact with the API:
![Swagger UI interaction](https://fastapi.tiangolo.com/img/index/index-04-swagger-03.png)
* Then click on the "Execute" button, the user interface will communicate with your API, send the parameters, get the results and show them on the screen:
![Swagger UI interaction](https://fastapi.tiangolo.com/img/index/index-05-swagger-04.png)
### Alternative API docs upgrade
And now, go to <a href="http://127.0.0.1:8000/redoc" target="_blank">http://127.0.0.1:8000/redoc</a>.
* The alternative documentation will also reflect the new query parameter and body:
![ReDoc](https://fastapi.tiangolo.com/img/index/index-06-redoc-02.png)
### Recap
In summary, you declare **once** the types of parameters, body, etc. as function parameters.
You do that with standard modern Python types.
You don't have to learn a new syntax, the methods or classes of a specific library, etc.
Just standard **Python 3.6+**.
For example, for an `int`:
```Python
item_id: int
```
or for a more complex `Item` model:
```Python
item: Item
```
...and with that single declaration you get:
* Editor support, including:
* Completion.
* Type checks.
* Validat
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
资源分类:Python库 所属语言:Python 资源全名:fastapi-0.11.0.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
Python库 | fastapi-0.11.0.tar.gz (402个子文件)
.gitignore 137B
mypy.ini 37B
LICENSE 1KB
Pipfile.lock 40KB
async.md 20KB
alternatives.md 20KB
index.md 14KB
README.md 14KB
release-notes.md 13KB
sql-databases.md 12KB
deployment.md 11KB
features.md 9KB
bigger-applications.md 9KB
first-steps.md 8KB
python-types.md 8KB
simple-oauth2.md 7KB
project-generation.md 7KB
oauth2-jwt.md 7KB
query-params-str-validations.md 7KB
first-steps.md 7KB
first-steps.md 7KB
body-nested-models.md 5KB
nosql-databases.md 5KB
classes-as-dependencies.md 5KB
body.md 5KB
extra-models.md 5KB
request-files.md 5KB
background-tasks.md 5KB
path-params.md 5KB
body-multiple-params.md 5KB
help-fastapi.md 4KB
async-sql-databases.md 4KB
query-params.md 4KB
history-design-future.md 4KB
get-current-user.md 4KB
path-params-numeric-validations.md 4KB
intro.md 4KB
handling-errors.md 4KB
contributing.md 4KB
sub-applications-proxy.md 4KB
custom-response.md 3KB
benchmarks.md 3KB
extending-openapi.md 3KB
path-operation-configuration.md 3KB
websockets.md 3KB
response-model.md 3KB
response-status-code.md 3KB
header-params.md 3KB
advanced-dependencies.md 3KB
extra-data-types.md 2KB
body-schema.md 2KB
request-forms.md 2KB
sub-dependencies.md 2KB
using-request-directly.md 2KB
debugging.md 2KB
events.md 2KB
application-configuration.md 2KB
intro.md 1KB
graphql.md 1KB
request-forms-and-files.md 1013B
cookie-params.md 839B
bug_report.md 833B
path-operation-advanced-configuration.md 668B
feature_request.md 633B
question.md 251B
Pipfile 570B
PKG-INFO 256B
image01.png 170KB
image10.png 155KB
image09.png 108KB
image01.png 93KB
image06.png 89KB
image02.png 87KB
image02.png 87KB
image08.png 86KB
image03.png 85KB
image01.png 84KB
image04.png 82KB
image02.png 82KB
image02.png 79KB
image02.png 79KB
image05.png 79KB
image01.png 78KB
image01.png 77KB
image01.png 77KB
index-06-redoc-02.png 77KB
image01.png 77KB
image01.png 74KB
index-03-swagger-02.png 73KB
image05.png 73KB
image01.png 73KB
index-01-swagger-ui-simple.png 72KB
image02.png 71KB
index-05-swagger-04.png 70KB
image03.png 69KB
image01.png 69KB
index-02-redoc-simple.png 67KB
index-04-swagger-03.png 66KB
image02.png 66KB
image02.png 65KB
共 402 条
- 1
- 2
- 3
- 4
- 5
资源评论
挣扎的蓝藻
- 粉丝: 14w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- python入门-17.最大子段和-团结!.py
- python入门-test-18.车厢重组.py
- 第56课 枚举2-20241227131043.pdf
- 基于 Flask 和 React 的前后端分离论坛全部资料+详细文档.zip
- 基于 Flask 和 WebSocket 实现的聊天室程序全部资料+详细文档.zip
- 基于 Scrapy 的新闻智能分类微信小程序,目的是打造出一个可以对新闻进行智能分类的微信小程序。技术栈:Python + Scrapy + MongoDB +
- 基于Flask 与Material Design的博客全部资料+详细文档.zip
- 基于bert4keras的命名实体识别flask展示全部资料+详细文档.zip
- 基于bert4keras关系抽取的flask展示全部资料+详细文档.zip
- 基于flask+MySQL的日程管理系统全部资料+详细文档.zip
- 基于Flask、MySQL和Bootstrap开发的图片分享社交网站。全部资料+详细文档.zip
- 基于Flask+Python3.6的电影网站项目全部资料+详细文档.zip
- 基于flask的web端三维模型重建系统-毕业设计全部资料+详细文档.zip
- 基于Flask的自然语言处理Web应用:人物观点提取,文本摘要,点评情感分类全部资料+详细文档.zip
- 基于Flask构建的无人机物流管理系统全部资料+详细文档.zip
- 基于flask框架的轻量级新闻资讯网站全部资料+详细文档.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功