๐ & ๐ฉบ ๐¶
๐ ๐ช ๐ ๐ ๐ ๐ณ ๐ FastAPI ๐ธ.
๐ ๐ ๏ธ¶
๐ ๐ช โ ๐ ๐ ๐ โ๏ธ ๐ ๐ง & ๐ง ๐ ๏ธ ๐ฉบ โ:
| ๐ข | ๐ | ๐ | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
title | 
str | 
๐ ๐ ๏ธ. | ||||||||||||
description | 
str | 
๐ ๐ ๐ ๏ธ. โซ๏ธ ๐ช โ๏ธ โ. | ||||||||||||
version | 
string | 
โฌ ๐ ๏ธ. ๐ โฌ ๐ ๐ ๐ธ, ๐ซ ๐. ๐ผ 2.5.0. | 
||||||||||||
terms_of_service | 
str | 
๐ โ ๐โ๐ฆบ ๐ ๏ธ. ๐ฅ ๐, ๐ โ๏ธ ๐. | ||||||||||||
contact | 
dict | 
๐ง โน ๐ฆ ๐ ๏ธ. โซ๏ธ ๐ช ๐ ๐ ๐. 
 | 
| ๐ข | ๐ | ๐ | 
|---|---|---|
name | str | โ ๐ ๐ง ๐จโ๐ผ/๐ข. | 
url | str | ๐ โ ๐ง โน. ๐ ๐ ๐. | 
email | str | ๐ง ๐ข ๐ง ๐จโ๐ผ/๐ข. ๐ ๐ ๐ง ๐ข. | 
license_infodictlicense_info ๐
| ๐ข | ๐ | ๐ | 
|---|---|---|
name | str | ๐ (๐ฅ license_info โ). ๐ ๐ โ๏ธ ๐ ๏ธ. | 
url | str | ๐ ๐ โ๏ธ ๐ ๏ธ. ๐ ๐ ๐. | 
๐ ๐ช โ ๐ซ โฉ:
from fastapi import FastAPI
description = """
ChimichangApp API helps you do awesome stuff. ๐
## Items
You can **read items**.
## Users
You will be able to:
* **Create users** (_not implemented_).
* **Read users** (_not implemented_).
"""
app = FastAPI(
    title="ChimichangApp",
    description=description,
    summary="Deadpool's favorite app. Nuff said.",
    version="0.0.1",
    terms_of_service="http://example.com/terms/",
    contact={
        "name": "Deadpoolio the Amazing",
        "url": "http://x-force.example.com/contact/",
        "email": "dp@x-force.example.com",
    },
    license_info={
        "name": "Apache 2.0",
        "url": "https://www.apache.org/licenses/LICENSE-2.0.html",
    },
)
@app.get("/items/")
async def read_items():
    return [{"name": "Katana"}]
Tip
๐ ๐ช โ โ description ๐ & โซ๏ธ ๐ โ ๐ข.
โฎ๏ธ ๐ ๐ณ, ๐ง ๐ ๏ธ ๐ฉบ ๐ ๐ ๐:

๐ ๐¶
๐ ๐ช ๐ฎ ๐ ๐ ๐ ๐ โ๏ธ ๐ช ๐ โก ๐ ๏ธ โฎ๏ธ ๐ข openapi_tags.
โซ๏ธ โ ๐ โ 1๏ธโฃ ๐ ๐ ๐.
๐ ๐ ๐ช ๐:
name(โ):strโฎ๏ธ ๐ ๐ ๐ โ๏ธtags๐ข ๐ โก ๐ ๏ธ &APIRouterโ.description:strโฎ๏ธ ๐ ๐ ๐. โซ๏ธ ๐ช โ๏ธ โ & ๐ ๐ฆ ๐ฉบ ๐.externalDocs:dict๐ฌ ๐ข ๐งพ โฎ๏ธ:description:strโฎ๏ธ ๐ ๐ ๐ข ๐ฉบ.url(โ):strโฎ๏ธ ๐ ๐ข ๐งพ.
โ ๐ ๐¶
โก๏ธ ๐ ๐ ๐ผ โฎ๏ธ ๐ users & items.
โ ๐ ๐ ๐ & ๐ถโโ๏ธ โซ๏ธ openapi_tags ๐ข:
from fastapi import FastAPI
tags_metadata = [
    {
        "name": "users",
        "description": "Operations with users. The **login** logic is also here.",
    },
    {
        "name": "items",
        "description": "Manage items. So _fancy_ they have their own docs.",
        "externalDocs": {
            "description": "Items external docs",
            "url": "https://fastapi.tiangolo.com/",
        },
    },
]
app = FastAPI(openapi_tags=tags_metadata)
@app.get("/users/", tags=["users"])
async def get_users():
    return [{"name": "Harry"}, {"name": "Ron"}]
@app.get("/items/", tags=["items"])
async def get_items():
    return [{"name": "wand"}, {"name": "flying broom"}]
๐ ๐ ๐ ๐ช โ๏ธ โ ๐ ๐, ๐ผ "๐ณ" ๐ ๐ฆ ๐ฆ (๐ณ) & "๐" ๐ ๐ฆ โ (๐).
Tip
๐ ๐ซ โ๏ธ ๐ฎ ๐ ๐ ๐ ๐ ๐ โ๏ธ.
โ๏ธ ๐ ๐¶
โ๏ธ tags ๐ข โฎ๏ธ ๐ โก ๐ ๏ธ (& APIRouterโ) ๐ ๏ธ ๐ซ ๐ ๐:
from fastapi import FastAPI
tags_metadata = [
    {
        "name": "users",
        "description": "Operations with users. The **login** logic is also here.",
    },
    {
        "name": "items",
        "description": "Manage items. So _fancy_ they have their own docs.",
        "externalDocs": {
            "description": "Items external docs",
            "url": "https://fastapi.tiangolo.com/",
        },
    },
]
app = FastAPI(openapi_tags=tags_metadata)
@app.get("/users/", tags=["users"])
async def get_users():
    return [{"name": "Harry"}, {"name": "Ron"}]
@app.get("/items/", tags=["items"])
async def get_items():
    return [{"name": "wand"}, {"name": "flying broom"}]
Info
โ ๐ ๐ ๐ โก ๐ ๏ธ ๐ณ.
โ ๐ฉบ¶
๐, ๐ฅ ๐ โ ๐ฉบ, ๐ซ ๐ ๐ฆ ๐ ๐ ๐:

โ ๐¶
โ ๐ ๐ ๐ ๐ ๐ฌ โ ๐ฆ ๐ฉบ ๐.
๐ผ, โ๏ธ users ๐ ๐ถ โฎ๏ธ items ๐ค โ, โซ๏ธ ๐ฆ โญ ๐ซ, โฉ๏ธ ๐ฅ ๐ฎ ๐ซ ๐ ๐ฅ ๐ ๐.
๐ ๐¶
๐ข, ๐ ๐ ๐ฆ /openapi.json.
โ๏ธ ๐ ๐ช ๐ โซ๏ธ โฎ๏ธ ๐ข openapi_url.
๐ผ, โ โซ๏ธ ๐ฆ /api/v1/openapi.json:
from fastapi import FastAPI
app = FastAPI(openapi_url="/api/v1/openapi.json")
@app.get("/items/")
async def read_items():
    return [{"name": "Foo"}]
๐ฅ ๐ ๐ โ ๐ ๐ ๐ ๐ ๐ช โ openapi_url=None, ๐ ๐ โ ๐งพ ๐ฉโ๐ป ๐ข ๐ โ๏ธ โซ๏ธ.
๐ฉบ ๐¶
๐ ๐ช ๐ 2๏ธโฃ ๐งพ ๐ฉโ๐ป ๐ข ๐:
- ๐ฆ ๐: ๐ฆ 
/docs.- ๐ ๐ช โ ๐ฎ ๐ โฎ๏ธ ๐ข 
docs_url. - ๐ ๐ช โ โซ๏ธ โ 
docs_url=None. 
 - ๐ ๐ช โ ๐ฎ ๐ โฎ๏ธ ๐ข 
 - ๐: ๐ฆ 
/redoc.- ๐ ๐ช โ ๐ฎ ๐ โฎ๏ธ ๐ข 
redoc_url. - ๐ ๐ช โ โซ๏ธ โ 
redoc_url=None. 
 - ๐ ๐ช โ ๐ฎ ๐ โฎ๏ธ ๐ข 
 
๐ผ, โ ๐ฆ ๐ ๐ฆ /documentation & โ ๐:
from fastapi import FastAPI
app = FastAPI(docs_url="/documentation", redoc_url=None)
@app.get("/items/")
async def read_items():
    return [{"name": "Foo"}]