repo stringlengths 7 90 | file_url stringlengths 81 315 | file_path stringlengths 4 228 | content stringlengths 0 32.8k | language stringclasses 1 value | license stringclasses 7 values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 14:38:15 2026-01-05 02:33:18 | truncated bool 2 classes |
|---|---|---|---|---|---|---|---|---|
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/response_model/tutorial006_py39.py | docs_src/response_model/tutorial006_py39.py | from typing import Union
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
description: Union[str, None] = None
price: float
tax: float = 10.5
items = {
"foo": {"name": "Foo", "price": 50.2},
"bar": {"name": "Bar", "description": "The Bar fighters", "price": 62, "tax": 20.2},
"baz": {
"name": "Baz",
"description": "There goes my baz",
"price": 50.2,
"tax": 10.5,
},
}
@app.get(
"/items/{item_id}/name",
response_model=Item,
response_model_include=["name", "description"],
)
async def read_item_name(item_id: str):
return items[item_id]
@app.get("/items/{item_id}/public", response_model=Item, response_model_exclude=["tax"])
async def read_item_public_data(item_id: str):
return items[item_id]
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/response_model/tutorial003_py310.py | docs_src/response_model/tutorial003_py310.py | from typing import Any
from fastapi import FastAPI
from pydantic import BaseModel, EmailStr
app = FastAPI()
class UserIn(BaseModel):
username: str
password: str
email: EmailStr
full_name: str | None = None
class UserOut(BaseModel):
username: str
email: EmailStr
full_name: str | None = None
@app.post("/user/", response_model=UserOut)
async def create_user(user: UserIn) -> Any:
return user
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/response_model/tutorial004_py310.py | docs_src/response_model/tutorial004_py310.py | from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
description: str | None = None
price: float
tax: float = 10.5
tags: list[str] = []
items = {
"foo": {"name": "Foo", "price": 50.2},
"bar": {"name": "Bar", "description": "The bartenders", "price": 62, "tax": 20.2},
"baz": {"name": "Baz", "description": None, "price": 50.2, "tax": 10.5, "tags": []},
}
@app.get("/items/{item_id}", response_model=Item, response_model_exclude_unset=True)
async def read_item(item_id: str):
return items[item_id]
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/response_model/tutorial003_04_py310.py | docs_src/response_model/tutorial003_04_py310.py | from fastapi import FastAPI, Response
from fastapi.responses import RedirectResponse
app = FastAPI()
@app.get("/portal")
async def get_portal(teleport: bool = False) -> Response | dict:
if teleport:
return RedirectResponse(url="https://www.youtube.com/watch?v=dQw4w9WgXcQ")
return {"message": "Here's your interdimensional portal."}
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/response_model/tutorial005_py310.py | docs_src/response_model/tutorial005_py310.py | from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
description: str | None = None
price: float
tax: float = 10.5
items = {
"foo": {"name": "Foo", "price": 50.2},
"bar": {"name": "Bar", "description": "The Bar fighters", "price": 62, "tax": 20.2},
"baz": {
"name": "Baz",
"description": "There goes my baz",
"price": 50.2,
"tax": 10.5,
},
}
@app.get(
"/items/{item_id}/name",
response_model=Item,
response_model_include={"name", "description"},
)
async def read_item_name(item_id: str):
return items[item_id]
@app.get("/items/{item_id}/public", response_model=Item, response_model_exclude={"tax"})
async def read_item_public_data(item_id: str):
return items[item_id]
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/response_model/tutorial006_py310.py | docs_src/response_model/tutorial006_py310.py | from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
description: str | None = None
price: float
tax: float = 10.5
items = {
"foo": {"name": "Foo", "price": 50.2},
"bar": {"name": "Bar", "description": "The Bar fighters", "price": 62, "tax": 20.2},
"baz": {
"name": "Baz",
"description": "There goes my baz",
"price": 50.2,
"tax": 10.5,
},
}
@app.get(
"/items/{item_id}/name",
response_model=Item,
response_model_include=["name", "description"],
)
async def read_item_name(item_id: str):
return items[item_id]
@app.get("/items/{item_id}/public", response_model=Item, response_model_exclude=["tax"])
async def read_item_public_data(item_id: str):
return items[item_id]
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/response_model/tutorial003_05_py39.py | docs_src/response_model/tutorial003_05_py39.py | from typing import Union
from fastapi import FastAPI, Response
from fastapi.responses import RedirectResponse
app = FastAPI()
@app.get("/portal", response_model=None)
async def get_portal(teleport: bool = False) -> Union[Response, dict]:
if teleport:
return RedirectResponse(url="https://www.youtube.com/watch?v=dQw4w9WgXcQ")
return {"message": "Here's your interdimensional portal."}
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/response_model/__init__.py | docs_src/response_model/__init__.py | python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false | |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/response_model/tutorial002_py310.py | docs_src/response_model/tutorial002_py310.py | from fastapi import FastAPI
from pydantic import BaseModel, EmailStr
app = FastAPI()
class UserIn(BaseModel):
username: str
password: str
email: EmailStr
full_name: str | None = None
# Don't do this in production!
@app.post("/user/")
async def create_user(user: UserIn) -> UserIn:
return user
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/response_model/tutorial001_py310.py | docs_src/response_model/tutorial001_py310.py | from typing import Any
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
description: str | None = None
price: float
tax: float | None = None
tags: list[str] = []
@app.post("/items/", response_model=Item)
async def create_item(item: Item) -> Any:
return item
@app.get("/items/", response_model=list[Item])
async def read_items() -> Any:
return [
{"name": "Portal Gun", "price": 42.0},
{"name": "Plumbus", "price": 32.0},
]
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/response_model/tutorial002_py39.py | docs_src/response_model/tutorial002_py39.py | from typing import Union
from fastapi import FastAPI
from pydantic import BaseModel, EmailStr
app = FastAPI()
class UserIn(BaseModel):
username: str
password: str
email: EmailStr
full_name: Union[str, None] = None
# Don't do this in production!
@app.post("/user/")
async def create_user(user: UserIn) -> UserIn:
return user
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/response_model/tutorial003_05_py310.py | docs_src/response_model/tutorial003_05_py310.py | from fastapi import FastAPI, Response
from fastapi.responses import RedirectResponse
app = FastAPI()
@app.get("/portal", response_model=None)
async def get_portal(teleport: bool = False) -> Response | dict:
if teleport:
return RedirectResponse(url="https://www.youtube.com/watch?v=dQw4w9WgXcQ")
return {"message": "Here's your interdimensional portal."}
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/response_model/tutorial003_py39.py | docs_src/response_model/tutorial003_py39.py | from typing import Any, Union
from fastapi import FastAPI
from pydantic import BaseModel, EmailStr
app = FastAPI()
class UserIn(BaseModel):
username: str
password: str
email: EmailStr
full_name: Union[str, None] = None
class UserOut(BaseModel):
username: str
email: EmailStr
full_name: Union[str, None] = None
@app.post("/user/", response_model=UserOut)
async def create_user(user: UserIn) -> Any:
return user
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/response_model/tutorial003_01_py39.py | docs_src/response_model/tutorial003_01_py39.py | from typing import Union
from fastapi import FastAPI
from pydantic import BaseModel, EmailStr
app = FastAPI()
class BaseUser(BaseModel):
username: str
email: EmailStr
full_name: Union[str, None] = None
class UserIn(BaseUser):
password: str
@app.post("/user/")
async def create_user(user: UserIn) -> BaseUser:
return user
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/response_model/tutorial003_02_py39.py | docs_src/response_model/tutorial003_02_py39.py | from fastapi import FastAPI, Response
from fastapi.responses import JSONResponse, RedirectResponse
app = FastAPI()
@app.get("/portal")
async def get_portal(teleport: bool = False) -> Response:
if teleport:
return RedirectResponse(url="https://www.youtube.com/watch?v=dQw4w9WgXcQ")
return JSONResponse(content={"message": "Here's your interdimensional portal."})
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial002_an_py310.py | docs_src/dependencies/tutorial002_an_py310.py | from typing import Annotated
from fastapi import Depends, FastAPI
app = FastAPI()
fake_items_db = [{"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}]
class CommonQueryParams:
def __init__(self, q: str | None = None, skip: int = 0, limit: int = 100):
self.q = q
self.skip = skip
self.limit = limit
@app.get("/items/")
async def read_items(commons: Annotated[CommonQueryParams, Depends(CommonQueryParams)]):
response = {}
if commons.q:
response.update({"q": commons.q})
items = fake_items_db[commons.skip : commons.skip + commons.limit]
response.update({"items": items})
return response
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial006_an_py39.py | docs_src/dependencies/tutorial006_an_py39.py | from typing import Annotated
from fastapi import Depends, FastAPI, Header, HTTPException
app = FastAPI()
async def verify_token(x_token: Annotated[str, Header()]):
if x_token != "fake-super-secret-token":
raise HTTPException(status_code=400, detail="X-Token header invalid")
async def verify_key(x_key: Annotated[str, Header()]):
if x_key != "fake-super-secret-key":
raise HTTPException(status_code=400, detail="X-Key header invalid")
return x_key
@app.get("/items/", dependencies=[Depends(verify_token), Depends(verify_key)])
async def read_items():
return [{"item": "Foo"}, {"item": "Bar"}]
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial005_an_py39.py | docs_src/dependencies/tutorial005_an_py39.py | from typing import Annotated, Union
from fastapi import Cookie, Depends, FastAPI
app = FastAPI()
def query_extractor(q: Union[str, None] = None):
return q
def query_or_cookie_extractor(
q: Annotated[str, Depends(query_extractor)],
last_query: Annotated[Union[str, None], Cookie()] = None,
):
if not q:
return last_query
return q
@app.get("/items/")
async def read_query(
query_or_default: Annotated[str, Depends(query_or_cookie_extractor)],
):
return {"q_or_cookie": query_or_default}
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial004_an_py310.py | docs_src/dependencies/tutorial004_an_py310.py | from typing import Annotated
from fastapi import Depends, FastAPI
app = FastAPI()
fake_items_db = [{"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}]
class CommonQueryParams:
def __init__(self, q: str | None = None, skip: int = 0, limit: int = 100):
self.q = q
self.skip = skip
self.limit = limit
@app.get("/items/")
async def read_items(commons: Annotated[CommonQueryParams, Depends()]):
response = {}
if commons.q:
response.update({"q": commons.q})
items = fake_items_db[commons.skip : commons.skip + commons.limit]
response.update({"items": items})
return response
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial005_an_py310.py | docs_src/dependencies/tutorial005_an_py310.py | from typing import Annotated
from fastapi import Cookie, Depends, FastAPI
app = FastAPI()
def query_extractor(q: str | None = None):
return q
def query_or_cookie_extractor(
q: Annotated[str, Depends(query_extractor)],
last_query: Annotated[str | None, Cookie()] = None,
):
if not q:
return last_query
return q
@app.get("/items/")
async def read_query(
query_or_default: Annotated[str, Depends(query_or_cookie_extractor)],
):
return {"q_or_cookie": query_or_default}
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial008c_py39.py | docs_src/dependencies/tutorial008c_py39.py | from fastapi import Depends, FastAPI, HTTPException
app = FastAPI()
class InternalError(Exception):
pass
def get_username():
try:
yield "Rick"
except InternalError:
print("Oops, we didn't raise again, Britney 😱")
@app.get("/items/{item_id}")
def get_item(item_id: str, username: str = Depends(get_username)):
if item_id == "portal-gun":
raise InternalError(
f"The portal gun is too dangerous to be owned by {username}"
)
if item_id != "plumbus":
raise HTTPException(
status_code=404, detail="Item not found, there's only a plumbus here"
)
return item_id
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial001_02_an_py310.py | docs_src/dependencies/tutorial001_02_an_py310.py | from typing import Annotated
from fastapi import Depends, FastAPI
app = FastAPI()
async def common_parameters(q: str | None = None, skip: int = 0, limit: int = 100):
return {"q": q, "skip": skip, "limit": limit}
CommonsDep = Annotated[dict, Depends(common_parameters)]
@app.get("/items/")
async def read_items(commons: CommonsDep):
return commons
@app.get("/users/")
async def read_users(commons: CommonsDep):
return commons
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial004_py39.py | docs_src/dependencies/tutorial004_py39.py | from typing import Union
from fastapi import Depends, FastAPI
app = FastAPI()
fake_items_db = [{"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}]
class CommonQueryParams:
def __init__(self, q: Union[str, None] = None, skip: int = 0, limit: int = 100):
self.q = q
self.skip = skip
self.limit = limit
@app.get("/items/")
async def read_items(commons: CommonQueryParams = Depends()):
response = {}
if commons.q:
response.update({"q": commons.q})
items = fake_items_db[commons.skip : commons.skip + commons.limit]
response.update({"items": items})
return response
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial002_an_py39.py | docs_src/dependencies/tutorial002_an_py39.py | from typing import Annotated, Union
from fastapi import Depends, FastAPI
app = FastAPI()
fake_items_db = [{"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}]
class CommonQueryParams:
def __init__(self, q: Union[str, None] = None, skip: int = 0, limit: int = 100):
self.q = q
self.skip = skip
self.limit = limit
@app.get("/items/")
async def read_items(commons: Annotated[CommonQueryParams, Depends(CommonQueryParams)]):
response = {}
if commons.q:
response.update({"q": commons.q})
items = fake_items_db[commons.skip : commons.skip + commons.limit]
response.update({"items": items})
return response
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial003_an_py39.py | docs_src/dependencies/tutorial003_an_py39.py | from typing import Annotated, Any, Union
from fastapi import Depends, FastAPI
app = FastAPI()
fake_items_db = [{"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}]
class CommonQueryParams:
def __init__(self, q: Union[str, None] = None, skip: int = 0, limit: int = 100):
self.q = q
self.skip = skip
self.limit = limit
@app.get("/items/")
async def read_items(commons: Annotated[Any, Depends(CommonQueryParams)]):
response = {}
if commons.q:
response.update({"q": commons.q})
items = fake_items_db[commons.skip : commons.skip + commons.limit]
response.update({"items": items})
return response
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial008c_an_py39.py | docs_src/dependencies/tutorial008c_an_py39.py | from typing import Annotated
from fastapi import Depends, FastAPI, HTTPException
app = FastAPI()
class InternalError(Exception):
pass
def get_username():
try:
yield "Rick"
except InternalError:
print("Oops, we didn't raise again, Britney 😱")
@app.get("/items/{item_id}")
def get_item(item_id: str, username: Annotated[str, Depends(get_username)]):
if item_id == "portal-gun":
raise InternalError(
f"The portal gun is too dangerous to be owned by {username}"
)
if item_id != "plumbus":
raise HTTPException(
status_code=404, detail="Item not found, there's only a plumbus here"
)
return item_id
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial001_py39.py | docs_src/dependencies/tutorial001_py39.py | from typing import Union
from fastapi import Depends, FastAPI
app = FastAPI()
async def common_parameters(
q: Union[str, None] = None, skip: int = 0, limit: int = 100
):
return {"q": q, "skip": skip, "limit": limit}
@app.get("/items/")
async def read_items(commons: dict = Depends(common_parameters)):
return commons
@app.get("/users/")
async def read_users(commons: dict = Depends(common_parameters)):
return commons
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial001_an_py39.py | docs_src/dependencies/tutorial001_an_py39.py | from typing import Annotated, Union
from fastapi import Depends, FastAPI
app = FastAPI()
async def common_parameters(
q: Union[str, None] = None, skip: int = 0, limit: int = 100
):
return {"q": q, "skip": skip, "limit": limit}
@app.get("/items/")
async def read_items(commons: Annotated[dict, Depends(common_parameters)]):
return commons
@app.get("/users/")
async def read_users(commons: Annotated[dict, Depends(common_parameters)]):
return commons
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial005_py39.py | docs_src/dependencies/tutorial005_py39.py | from typing import Union
from fastapi import Cookie, Depends, FastAPI
app = FastAPI()
def query_extractor(q: Union[str, None] = None):
return q
def query_or_cookie_extractor(
q: str = Depends(query_extractor),
last_query: Union[str, None] = Cookie(default=None),
):
if not q:
return last_query
return q
@app.get("/items/")
async def read_query(query_or_default: str = Depends(query_or_cookie_extractor)):
return {"q_or_cookie": query_or_default}
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial003_an_py310.py | docs_src/dependencies/tutorial003_an_py310.py | from typing import Annotated, Any
from fastapi import Depends, FastAPI
app = FastAPI()
fake_items_db = [{"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}]
class CommonQueryParams:
def __init__(self, q: str | None = None, skip: int = 0, limit: int = 100):
self.q = q
self.skip = skip
self.limit = limit
@app.get("/items/")
async def read_items(commons: Annotated[Any, Depends(CommonQueryParams)]):
response = {}
if commons.q:
response.update({"q": commons.q})
items = fake_items_db[commons.skip : commons.skip + commons.limit]
response.update({"items": items})
return response
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial008d_an_py39.py | docs_src/dependencies/tutorial008d_an_py39.py | from typing import Annotated
from fastapi import Depends, FastAPI, HTTPException
app = FastAPI()
class InternalError(Exception):
pass
def get_username():
try:
yield "Rick"
except InternalError:
print("We don't swallow the internal error here, we raise again 😎")
raise
@app.get("/items/{item_id}")
def get_item(item_id: str, username: Annotated[str, Depends(get_username)]):
if item_id == "portal-gun":
raise InternalError(
f"The portal gun is too dangerous to be owned by {username}"
)
if item_id != "plumbus":
raise HTTPException(
status_code=404, detail="Item not found, there's only a plumbus here"
)
return item_id
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial007_py39.py | docs_src/dependencies/tutorial007_py39.py | async def get_db():
db = DBSession()
try:
yield db
finally:
db.close()
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial014_an_py310.py | docs_src/dependencies/tutorial014_an_py310.py | import time
from typing import Annotated
from fastapi import Depends, FastAPI, HTTPException
from fastapi.responses import StreamingResponse
from sqlmodel import Field, Session, SQLModel, create_engine
engine = create_engine("postgresql+psycopg://postgres:postgres@localhost/db")
class User(SQLModel, table=True):
id: int | None = Field(default=None, primary_key=True)
name: str
app = FastAPI()
def get_session():
with Session(engine) as session:
yield session
def get_user(user_id: int, session: Annotated[Session, Depends(get_session)]):
user = session.get(User, user_id)
if not user:
raise HTTPException(status_code=403, detail="Not authorized")
session.close()
def generate_stream(query: str):
for ch in query:
yield ch
time.sleep(0.1)
@app.get("/generate", dependencies=[Depends(get_user)])
def generate(query: str):
return StreamingResponse(content=generate_stream(query))
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial008e_an_py39.py | docs_src/dependencies/tutorial008e_an_py39.py | from typing import Annotated
from fastapi import Depends, FastAPI
app = FastAPI()
def get_username():
try:
yield "Rick"
finally:
print("Cleanup up before response is sent")
@app.get("/users/me")
def get_user_me(username: Annotated[str, Depends(get_username, scope="function")]):
return username
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial010_py39.py | docs_src/dependencies/tutorial010_py39.py | class MySuperContextManager:
def __init__(self):
self.db = DBSession()
def __enter__(self):
return self.db
def __exit__(self, exc_type, exc_value, traceback):
self.db.close()
async def get_db():
with MySuperContextManager() as db:
yield db
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial006_py39.py | docs_src/dependencies/tutorial006_py39.py | from fastapi import Depends, FastAPI, Header, HTTPException
app = FastAPI()
async def verify_token(x_token: str = Header()):
if x_token != "fake-super-secret-token":
raise HTTPException(status_code=400, detail="X-Token header invalid")
async def verify_key(x_key: str = Header()):
if x_key != "fake-super-secret-key":
raise HTTPException(status_code=400, detail="X-Key header invalid")
return x_key
@app.get("/items/", dependencies=[Depends(verify_token), Depends(verify_key)])
async def read_items():
return [{"item": "Foo"}, {"item": "Bar"}]
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial008e_py39.py | docs_src/dependencies/tutorial008e_py39.py | from fastapi import Depends, FastAPI
app = FastAPI()
def get_username():
try:
yield "Rick"
finally:
print("Cleanup up before response is sent")
@app.get("/users/me")
def get_user_me(username: str = Depends(get_username, scope="function")):
return username
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial008_an_py39.py | docs_src/dependencies/tutorial008_an_py39.py | from typing import Annotated
from fastapi import Depends
async def dependency_a():
dep_a = generate_dep_a()
try:
yield dep_a
finally:
dep_a.close()
async def dependency_b(dep_a: Annotated[DepA, Depends(dependency_a)]):
dep_b = generate_dep_b()
try:
yield dep_b
finally:
dep_b.close(dep_a)
async def dependency_c(dep_b: Annotated[DepB, Depends(dependency_b)]):
dep_c = generate_dep_c()
try:
yield dep_c
finally:
dep_c.close(dep_b)
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial008_py39.py | docs_src/dependencies/tutorial008_py39.py | from fastapi import Depends
async def dependency_a():
dep_a = generate_dep_a()
try:
yield dep_a
finally:
dep_a.close()
async def dependency_b(dep_a=Depends(dependency_a)):
dep_b = generate_dep_b()
try:
yield dep_b
finally:
dep_b.close(dep_a)
async def dependency_c(dep_b=Depends(dependency_b)):
dep_c = generate_dep_c()
try:
yield dep_c
finally:
dep_c.close(dep_b)
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial008b_an_py39.py | docs_src/dependencies/tutorial008b_an_py39.py | from typing import Annotated
from fastapi import Depends, FastAPI, HTTPException
app = FastAPI()
data = {
"plumbus": {"description": "Freshly pickled plumbus", "owner": "Morty"},
"portal-gun": {"description": "Gun to create portals", "owner": "Rick"},
}
class OwnerError(Exception):
pass
def get_username():
try:
yield "Rick"
except OwnerError as e:
raise HTTPException(status_code=400, detail=f"Owner error: {e}")
@app.get("/items/{item_id}")
def get_item(item_id: str, username: Annotated[str, Depends(get_username)]):
if item_id not in data:
raise HTTPException(status_code=404, detail="Item not found")
item = data[item_id]
if item["owner"] != username:
raise OwnerError(username)
return item
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial003_py310.py | docs_src/dependencies/tutorial003_py310.py | from fastapi import Depends, FastAPI
app = FastAPI()
fake_items_db = [{"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}]
class CommonQueryParams:
def __init__(self, q: str | None = None, skip: int = 0, limit: int = 100):
self.q = q
self.skip = skip
self.limit = limit
@app.get("/items/")
async def read_items(commons=Depends(CommonQueryParams)):
response = {}
if commons.q:
response.update({"q": commons.q})
items = fake_items_db[commons.skip : commons.skip + commons.limit]
response.update({"items": items})
return response
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial013_an_py310.py | docs_src/dependencies/tutorial013_an_py310.py | import time
from typing import Annotated
from fastapi import Depends, FastAPI, HTTPException
from fastapi.responses import StreamingResponse
from sqlmodel import Field, Session, SQLModel, create_engine
engine = create_engine("postgresql+psycopg://postgres:postgres@localhost/db")
class User(SQLModel, table=True):
id: int | None = Field(default=None, primary_key=True)
name: str
app = FastAPI()
def get_session():
with Session(engine) as session:
yield session
def get_user(user_id: int, session: Annotated[Session, Depends(get_session)]):
user = session.get(User, user_id)
if not user:
raise HTTPException(status_code=403, detail="Not authorized")
def generate_stream(query: str):
for ch in query:
yield ch
time.sleep(0.1)
@app.get("/generate", dependencies=[Depends(get_user)])
def generate(query: str):
return StreamingResponse(content=generate_stream(query))
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial008b_py39.py | docs_src/dependencies/tutorial008b_py39.py | from fastapi import Depends, FastAPI, HTTPException
app = FastAPI()
data = {
"plumbus": {"description": "Freshly pickled plumbus", "owner": "Morty"},
"portal-gun": {"description": "Gun to create portals", "owner": "Rick"},
}
class OwnerError(Exception):
pass
def get_username():
try:
yield "Rick"
except OwnerError as e:
raise HTTPException(status_code=400, detail=f"Owner error: {e}")
@app.get("/items/{item_id}")
def get_item(item_id: str, username: str = Depends(get_username)):
if item_id not in data:
raise HTTPException(status_code=404, detail="Item not found")
item = data[item_id]
if item["owner"] != username:
raise OwnerError(username)
return item
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial012_py39.py | docs_src/dependencies/tutorial012_py39.py | from fastapi import Depends, FastAPI, Header, HTTPException
async def verify_token(x_token: str = Header()):
if x_token != "fake-super-secret-token":
raise HTTPException(status_code=400, detail="X-Token header invalid")
async def verify_key(x_key: str = Header()):
if x_key != "fake-super-secret-key":
raise HTTPException(status_code=400, detail="X-Key header invalid")
return x_key
app = FastAPI(dependencies=[Depends(verify_token), Depends(verify_key)])
@app.get("/items/")
async def read_items():
return [{"item": "Portal Gun"}, {"item": "Plumbus"}]
@app.get("/users/")
async def read_users():
return [{"username": "Rick"}, {"username": "Morty"}]
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial001_02_an_py39.py | docs_src/dependencies/tutorial001_02_an_py39.py | from typing import Annotated, Union
from fastapi import Depends, FastAPI
app = FastAPI()
async def common_parameters(
q: Union[str, None] = None, skip: int = 0, limit: int = 100
):
return {"q": q, "skip": skip, "limit": limit}
CommonsDep = Annotated[dict, Depends(common_parameters)]
@app.get("/items/")
async def read_items(commons: CommonsDep):
return commons
@app.get("/users/")
async def read_users(commons: CommonsDep):
return commons
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial004_py310.py | docs_src/dependencies/tutorial004_py310.py | from fastapi import Depends, FastAPI
app = FastAPI()
fake_items_db = [{"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}]
class CommonQueryParams:
def __init__(self, q: str | None = None, skip: int = 0, limit: int = 100):
self.q = q
self.skip = skip
self.limit = limit
@app.get("/items/")
async def read_items(commons: CommonQueryParams = Depends()):
response = {}
if commons.q:
response.update({"q": commons.q})
items = fake_items_db[commons.skip : commons.skip + commons.limit]
response.update({"items": items})
return response
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial005_py310.py | docs_src/dependencies/tutorial005_py310.py | from fastapi import Cookie, Depends, FastAPI
app = FastAPI()
def query_extractor(q: str | None = None):
return q
def query_or_cookie_extractor(
q: str = Depends(query_extractor), last_query: str | None = Cookie(default=None)
):
if not q:
return last_query
return q
@app.get("/items/")
async def read_query(query_or_default: str = Depends(query_or_cookie_extractor)):
return {"q_or_cookie": query_or_default}
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial008d_py39.py | docs_src/dependencies/tutorial008d_py39.py | from fastapi import Depends, FastAPI, HTTPException
app = FastAPI()
class InternalError(Exception):
pass
def get_username():
try:
yield "Rick"
except InternalError:
print("We don't swallow the internal error here, we raise again 😎")
raise
@app.get("/items/{item_id}")
def get_item(item_id: str, username: str = Depends(get_username)):
if item_id == "portal-gun":
raise InternalError(
f"The portal gun is too dangerous to be owned by {username}"
)
if item_id != "plumbus":
raise HTTPException(
status_code=404, detail="Item not found, there's only a plumbus here"
)
return item_id
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/__init__.py | docs_src/dependencies/__init__.py | python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false | |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial002_py310.py | docs_src/dependencies/tutorial002_py310.py | from fastapi import Depends, FastAPI
app = FastAPI()
fake_items_db = [{"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}]
class CommonQueryParams:
def __init__(self, q: str | None = None, skip: int = 0, limit: int = 100):
self.q = q
self.skip = skip
self.limit = limit
@app.get("/items/")
async def read_items(commons: CommonQueryParams = Depends(CommonQueryParams)):
response = {}
if commons.q:
response.update({"q": commons.q})
items = fake_items_db[commons.skip : commons.skip + commons.limit]
response.update({"items": items})
return response
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial001_an_py310.py | docs_src/dependencies/tutorial001_an_py310.py | from typing import Annotated
from fastapi import Depends, FastAPI
app = FastAPI()
async def common_parameters(q: str | None = None, skip: int = 0, limit: int = 100):
return {"q": q, "skip": skip, "limit": limit}
@app.get("/items/")
async def read_items(commons: Annotated[dict, Depends(common_parameters)]):
return commons
@app.get("/users/")
async def read_users(commons: Annotated[dict, Depends(common_parameters)]):
return commons
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial011_py39.py | docs_src/dependencies/tutorial011_py39.py | from fastapi import Depends, FastAPI
app = FastAPI()
class FixedContentQueryChecker:
def __init__(self, fixed_content: str):
self.fixed_content = fixed_content
def __call__(self, q: str = ""):
if q:
return self.fixed_content in q
return False
checker = FixedContentQueryChecker("bar")
@app.get("/query-checker/")
async def read_query_check(fixed_content_included: bool = Depends(checker)):
return {"fixed_content_in_query": fixed_content_included}
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial001_py310.py | docs_src/dependencies/tutorial001_py310.py | from fastapi import Depends, FastAPI
app = FastAPI()
async def common_parameters(q: str | None = None, skip: int = 0, limit: int = 100):
return {"q": q, "skip": skip, "limit": limit}
@app.get("/items/")
async def read_items(commons: dict = Depends(common_parameters)):
return commons
@app.get("/users/")
async def read_users(commons: dict = Depends(common_parameters)):
return commons
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial004_an_py39.py | docs_src/dependencies/tutorial004_an_py39.py | from typing import Annotated, Union
from fastapi import Depends, FastAPI
app = FastAPI()
fake_items_db = [{"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}]
class CommonQueryParams:
def __init__(self, q: Union[str, None] = None, skip: int = 0, limit: int = 100):
self.q = q
self.skip = skip
self.limit = limit
@app.get("/items/")
async def read_items(commons: Annotated[CommonQueryParams, Depends()]):
response = {}
if commons.q:
response.update({"q": commons.q})
items = fake_items_db[commons.skip : commons.skip + commons.limit]
response.update({"items": items})
return response
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial002_py39.py | docs_src/dependencies/tutorial002_py39.py | from typing import Union
from fastapi import Depends, FastAPI
app = FastAPI()
fake_items_db = [{"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}]
class CommonQueryParams:
def __init__(self, q: Union[str, None] = None, skip: int = 0, limit: int = 100):
self.q = q
self.skip = skip
self.limit = limit
@app.get("/items/")
async def read_items(commons: CommonQueryParams = Depends(CommonQueryParams)):
response = {}
if commons.q:
response.update({"q": commons.q})
items = fake_items_db[commons.skip : commons.skip + commons.limit]
response.update({"items": items})
return response
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial011_an_py39.py | docs_src/dependencies/tutorial011_an_py39.py | from typing import Annotated
from fastapi import Depends, FastAPI
app = FastAPI()
class FixedContentQueryChecker:
def __init__(self, fixed_content: str):
self.fixed_content = fixed_content
def __call__(self, q: str = ""):
if q:
return self.fixed_content in q
return False
checker = FixedContentQueryChecker("bar")
@app.get("/query-checker/")
async def read_query_check(fixed_content_included: Annotated[bool, Depends(checker)]):
return {"fixed_content_in_query": fixed_content_included}
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial003_py39.py | docs_src/dependencies/tutorial003_py39.py | from typing import Union
from fastapi import Depends, FastAPI
app = FastAPI()
fake_items_db = [{"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}]
class CommonQueryParams:
def __init__(self, q: Union[str, None] = None, skip: int = 0, limit: int = 100):
self.q = q
self.skip = skip
self.limit = limit
@app.get("/items/")
async def read_items(commons=Depends(CommonQueryParams)):
response = {}
if commons.q:
response.update({"q": commons.q})
items = fake_items_db[commons.skip : commons.skip + commons.limit]
response.update({"items": items})
return response
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/dependencies/tutorial012_an_py39.py | docs_src/dependencies/tutorial012_an_py39.py | from typing import Annotated
from fastapi import Depends, FastAPI, Header, HTTPException
async def verify_token(x_token: Annotated[str, Header()]):
if x_token != "fake-super-secret-token":
raise HTTPException(status_code=400, detail="X-Token header invalid")
async def verify_key(x_key: Annotated[str, Header()]):
if x_key != "fake-super-secret-key":
raise HTTPException(status_code=400, detail="X-Key header invalid")
return x_key
app = FastAPI(dependencies=[Depends(verify_token), Depends(verify_key)])
@app.get("/items/")
async def read_items():
return [{"item": "Portal Gun"}, {"item": "Plumbus"}]
@app.get("/users/")
async def read_users():
return [{"username": "Rick"}, {"username": "Morty"}]
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/python_types/tutorial008b_py310.py | docs_src/python_types/tutorial008b_py310.py | def process_item(item: int | str):
print(item)
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/python_types/tutorial009b_py39.py | docs_src/python_types/tutorial009b_py39.py | from typing import Union
def say_hi(name: Union[str, None] = None):
if name is not None:
print(f"Hey {name}!")
else:
print("Hello World")
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/python_types/tutorial004_py39.py | docs_src/python_types/tutorial004_py39.py | def get_name_with_age(name: str, age: int):
name_with_age = name + " is this old: " + str(age)
return name_with_age
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/python_types/tutorial001_py39.py | docs_src/python_types/tutorial001_py39.py | def get_full_name(first_name, last_name):
full_name = first_name.title() + " " + last_name.title()
return full_name
print(get_full_name("john", "doe"))
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/python_types/tutorial005_py39.py | docs_src/python_types/tutorial005_py39.py | def get_items(item_a: str, item_b: int, item_c: float, item_d: bool, item_e: bytes):
return item_a, item_b, item_c, item_d, item_e
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/python_types/tutorial009c_py39.py | docs_src/python_types/tutorial009c_py39.py | from typing import Optional
def say_hi(name: Optional[str]):
print(f"Hey {name}!")
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/python_types/tutorial009_py310.py | docs_src/python_types/tutorial009_py310.py | def say_hi(name: str | None = None):
if name is not None:
print(f"Hey {name}!")
else:
print("Hello World")
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/python_types/tutorial007_py39.py | docs_src/python_types/tutorial007_py39.py | def process_items(items_t: tuple[int, int, str], items_s: set[bytes]):
return items_t, items_s
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/python_types/tutorial010_py39.py | docs_src/python_types/tutorial010_py39.py | class Person:
def __init__(self, name: str):
self.name = name
def get_person_name(one_person: Person):
return one_person.name
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/python_types/tutorial009c_py310.py | docs_src/python_types/tutorial009c_py310.py | def say_hi(name: str | None):
print(f"Hey {name}!")
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/python_types/tutorial006_py39.py | docs_src/python_types/tutorial006_py39.py | def process_items(items: list[str]):
for item in items:
print(item)
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/python_types/tutorial008_py39.py | docs_src/python_types/tutorial008_py39.py | def process_items(prices: dict[str, float]):
for item_name, item_price in prices.items():
print(item_name)
print(item_price)
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/python_types/tutorial008b_py39.py | docs_src/python_types/tutorial008b_py39.py | from typing import Union
def process_item(item: Union[int, str]):
print(item)
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/python_types/tutorial012_py39.py | docs_src/python_types/tutorial012_py39.py | from typing import Optional
from pydantic import BaseModel
class User(BaseModel):
name: str
age: Optional[int]
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/python_types/tutorial009_py39.py | docs_src/python_types/tutorial009_py39.py | from typing import Optional
def say_hi(name: Optional[str] = None):
if name is not None:
print(f"Hey {name}!")
else:
print("Hello World")
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/python_types/tutorial013_py39.py | docs_src/python_types/tutorial013_py39.py | from typing import Annotated
def say_hello(name: Annotated[str, "this is just metadata"]) -> str:
return f"Hello {name}"
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/python_types/__init__.py | docs_src/python_types/__init__.py | python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false | |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/python_types/tutorial011_py39.py | docs_src/python_types/tutorial011_py39.py | from datetime import datetime
from typing import Union
from pydantic import BaseModel
class User(BaseModel):
id: int
name: str = "John Doe"
signup_ts: Union[datetime, None] = None
friends: list[int] = []
external_data = {
"id": "123",
"signup_ts": "2017-06-01 12:22",
"friends": [1, "2", b"3"],
}
user = User(**external_data)
print(user)
# > User id=123 name='John Doe' signup_ts=datetime.datetime(2017, 6, 1, 12, 22) friends=[1, 2, 3]
print(user.id)
# > 123
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/python_types/tutorial002_py39.py | docs_src/python_types/tutorial002_py39.py | def get_full_name(first_name: str, last_name: str):
full_name = first_name.title() + " " + last_name.title()
return full_name
print(get_full_name("john", "doe"))
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/python_types/tutorial011_py310.py | docs_src/python_types/tutorial011_py310.py | from datetime import datetime
from pydantic import BaseModel
class User(BaseModel):
id: int
name: str = "John Doe"
signup_ts: datetime | None = None
friends: list[int] = []
external_data = {
"id": "123",
"signup_ts": "2017-06-01 12:22",
"friends": [1, "2", b"3"],
}
user = User(**external_data)
print(user)
# > User id=123 name='John Doe' signup_ts=datetime.datetime(2017, 6, 1, 12, 22) friends=[1, 2, 3]
print(user.id)
# > 123
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/python_types/tutorial003_py39.py | docs_src/python_types/tutorial003_py39.py | def get_name_with_age(name: str, age: int):
name_with_age = name + " is this old: " + age
return name_with_age
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/cookie_param_models/tutorial002_an_py310.py | docs_src/cookie_param_models/tutorial002_an_py310.py | from typing import Annotated
from fastapi import Cookie, FastAPI
from pydantic import BaseModel
app = FastAPI()
class Cookies(BaseModel):
model_config = {"extra": "forbid"}
session_id: str
fatebook_tracker: str | None = None
googall_tracker: str | None = None
@app.get("/items/")
async def read_items(cookies: Annotated[Cookies, Cookie()]):
return cookies
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/cookie_param_models/tutorial002_an_py39.py | docs_src/cookie_param_models/tutorial002_an_py39.py | from typing import Annotated, Union
from fastapi import Cookie, FastAPI
from pydantic import BaseModel
app = FastAPI()
class Cookies(BaseModel):
model_config = {"extra": "forbid"}
session_id: str
fatebook_tracker: Union[str, None] = None
googall_tracker: Union[str, None] = None
@app.get("/items/")
async def read_items(cookies: Annotated[Cookies, Cookie()]):
return cookies
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/cookie_param_models/tutorial001_py39.py | docs_src/cookie_param_models/tutorial001_py39.py | from typing import Union
from fastapi import Cookie, FastAPI
from pydantic import BaseModel
app = FastAPI()
class Cookies(BaseModel):
session_id: str
fatebook_tracker: Union[str, None] = None
googall_tracker: Union[str, None] = None
@app.get("/items/")
async def read_items(cookies: Cookies = Cookie()):
return cookies
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/cookie_param_models/tutorial001_an_py39.py | docs_src/cookie_param_models/tutorial001_an_py39.py | from typing import Annotated, Union
from fastapi import Cookie, FastAPI
from pydantic import BaseModel
app = FastAPI()
class Cookies(BaseModel):
session_id: str
fatebook_tracker: Union[str, None] = None
googall_tracker: Union[str, None] = None
@app.get("/items/")
async def read_items(cookies: Annotated[Cookies, Cookie()]):
return cookies
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/cookie_param_models/__init__.py | docs_src/cookie_param_models/__init__.py | python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false | |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/cookie_param_models/tutorial002_py310.py | docs_src/cookie_param_models/tutorial002_py310.py | from fastapi import Cookie, FastAPI
from pydantic import BaseModel
app = FastAPI()
class Cookies(BaseModel):
model_config = {"extra": "forbid"}
session_id: str
fatebook_tracker: str | None = None
googall_tracker: str | None = None
@app.get("/items/")
async def read_items(cookies: Cookies = Cookie()):
return cookies
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/cookie_param_models/tutorial001_an_py310.py | docs_src/cookie_param_models/tutorial001_an_py310.py | from typing import Annotated
from fastapi import Cookie, FastAPI
from pydantic import BaseModel
app = FastAPI()
class Cookies(BaseModel):
session_id: str
fatebook_tracker: str | None = None
googall_tracker: str | None = None
@app.get("/items/")
async def read_items(cookies: Annotated[Cookies, Cookie()]):
return cookies
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/cookie_param_models/tutorial001_py310.py | docs_src/cookie_param_models/tutorial001_py310.py | from fastapi import Cookie, FastAPI
from pydantic import BaseModel
app = FastAPI()
class Cookies(BaseModel):
session_id: str
fatebook_tracker: str | None = None
googall_tracker: str | None = None
@app.get("/items/")
async def read_items(cookies: Cookies = Cookie()):
return cookies
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/cookie_param_models/tutorial002_py39.py | docs_src/cookie_param_models/tutorial002_py39.py | from typing import Union
from fastapi import Cookie, FastAPI
from pydantic import BaseModel
app = FastAPI()
class Cookies(BaseModel):
model_config = {"extra": "forbid"}
session_id: str
fatebook_tracker: Union[str, None] = None
googall_tracker: Union[str, None] = None
@app.get("/items/")
async def read_items(cookies: Cookies = Cookie()):
return cookies
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/debugging/tutorial001_py39.py | docs_src/debugging/tutorial001_py39.py | import uvicorn
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def root():
a = "a"
b = "b" + a
return {"hello world": b}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/debugging/__init__.py | docs_src/debugging/__init__.py | python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false | |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/response_directly/tutorial001_py39.py | docs_src/response_directly/tutorial001_py39.py | from datetime import datetime
from typing import Union
from fastapi import FastAPI
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse
from pydantic import BaseModel
class Item(BaseModel):
title: str
timestamp: datetime
description: Union[str, None] = None
app = FastAPI()
@app.put("/items/{id}")
def update_item(id: str, item: Item):
json_compatible_item_data = jsonable_encoder(item)
return JSONResponse(content=json_compatible_item_data)
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/response_directly/__init__.py | docs_src/response_directly/__init__.py | python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false | |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/response_directly/tutorial001_py310.py | docs_src/response_directly/tutorial001_py310.py | from datetime import datetime
from fastapi import FastAPI
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse
from pydantic import BaseModel
class Item(BaseModel):
title: str
timestamp: datetime
description: str | None = None
app = FastAPI()
@app.put("/items/{id}")
def update_item(id: str, item: Item):
json_compatible_item_data = jsonable_encoder(item)
return JSONResponse(content=json_compatible_item_data)
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/response_directly/tutorial002_py39.py | docs_src/response_directly/tutorial002_py39.py | from fastapi import FastAPI, Response
app = FastAPI()
@app.get("/legacy/")
def get_legacy_data():
data = """<?xml version="1.0"?>
<shampoo>
<Header>
Apply shampoo here.
</Header>
<Body>
You'll have to use soap here.
</Body>
</shampoo>
"""
return Response(content=data, media_type="application/xml")
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/wsgi/tutorial001_py39.py | docs_src/wsgi/tutorial001_py39.py | from fastapi import FastAPI
from fastapi.middleware.wsgi import WSGIMiddleware
from flask import Flask, request
from markupsafe import escape
flask_app = Flask(__name__)
@flask_app.route("/")
def flask_main():
name = request.args.get("name", "World")
return f"Hello, {escape(name)} from Flask!"
app = FastAPI()
@app.get("/v2")
def read_main():
return {"message": "Hello World"}
app.mount("/v1", WSGIMiddleware(flask_app))
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/wsgi/__init__.py | docs_src/wsgi/__init__.py | python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false | |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/generate_clients/tutorial004_py39.py | docs_src/generate_clients/tutorial004_py39.py | import json
from pathlib import Path
file_path = Path("./openapi.json")
openapi_content = json.loads(file_path.read_text())
for path_data in openapi_content["paths"].values():
for operation in path_data.values():
tag = operation["tags"][0]
operation_id = operation["operationId"]
to_remove = f"{tag}-"
new_operation_id = operation_id[len(to_remove) :]
operation["operationId"] = new_operation_id
file_path.write_text(json.dumps(openapi_content))
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/generate_clients/tutorial001_py39.py | docs_src/generate_clients/tutorial001_py39.py | from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
price: float
class ResponseMessage(BaseModel):
message: str
@app.post("/items/", response_model=ResponseMessage)
async def create_item(item: Item):
return {"message": "item received"}
@app.get("/items/", response_model=list[Item])
async def get_items():
return [
{"name": "Plumbus", "price": 3},
{"name": "Portal Gun", "price": 9001},
]
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/generate_clients/__init__.py | docs_src/generate_clients/__init__.py | python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false | |
fastapi/fastapi | https://github.com/fastapi/fastapi/blob/f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a/docs_src/generate_clients/tutorial002_py39.py | docs_src/generate_clients/tutorial002_py39.py | from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
price: float
class ResponseMessage(BaseModel):
message: str
class User(BaseModel):
username: str
email: str
@app.post("/items/", response_model=ResponseMessage, tags=["items"])
async def create_item(item: Item):
return {"message": "Item received"}
@app.get("/items/", response_model=list[Item], tags=["items"])
async def get_items():
return [
{"name": "Plumbus", "price": 3},
{"name": "Portal Gun", "price": 9001},
]
@app.post("/users/", response_model=ResponseMessage, tags=["users"])
async def create_user(user: User):
return {"message": "User received"}
| python | MIT | f2687dc1bb01f4cb62eee90e656b61c38c2aaf6a | 2026-01-04T14:38:15.465144Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.