From b0d62b3410d6c6a52eb19167c864872e58bed912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 13 Dec 2018 21:48:37 +0400 Subject: [PATCH] :art: Lint and format tutorial src files --- docs/tutorial/src/tutorial01.py | 1 + docs/tutorial/src/tutorial02.py | 1 + docs/tutorial/src/tutorial03.py | 1 + docs/tutorial/src/tutorial04.py | 4 +++- docs/tutorial/src/tutorial05.py | 7 ++----- docs/tutorial/src/tutorial06.py | 2 +- docs/tutorial/src/tutorial07.py | 5 ++++- docs/tutorial/src/tutorial08.py | 9 +++++++-- docs/tutorial/src/tutorial09.py | 9 +++++++-- docs/tutorial/src/tutorial10.py | 2 ++ docs/tutorial/src/tutorial11.py | 2 ++ docs/tutorial/src/tutorial12.py | 2 ++ docs/tutorial/src/tutorial13.py | 2 ++ docs/tutorial/src/tutorial16.py | 4 +++- docs/tutorial/src/tutorial23.py | 2 +- docs/tutorial/src/tutorial24.py | 5 ++--- docs/tutorial/src/tutorial25.py | 6 ++---- docs/tutorial/src/tutorial26.py | 6 ++---- docs/tutorial/src/tutorial27.py | 2 +- docs/tutorial/src/tutorial28.py | 2 +- docs/tutorial/src/tutorial29.py | 2 +- docs/tutorial/src/tutorial30.py | 9 ++------- docs/tutorial/src/tutorial31.py | 15 ++++++++------- docs/tutorial/src/tutorial32.py | 9 +++++++-- docs/tutorial/src/tutorial33.py | 8 ++------ docs/tutorial/src/tutorial34.py | 8 ++------ docs/tutorial/src/tutorial35.py | 8 ++------ docs/tutorial/src/tutorial36.py | 11 ++++------- docs/tutorial/src/tutorial37.py | 11 ++++------- docs/tutorial/src/tutorial38.py | 11 ++++------- docs/tutorial/src/tutorial39.py | 11 ++++------- docs/tutorial/src/tutorial40.py | 11 ++++------- docs/tutorial/src/tutorial41.py | 5 +++-- docs/tutorial/src/tutorial42.py | 5 +++-- docs/tutorial/src/tutorial43.py | 5 +---- docs/tutorial/src/tutorial44.py | 3 --- docs/tutorial/src/tutorial45.py | 3 --- docs/tutorial/src/tutorial46.py | 6 +++--- docs/tutorial/src/tutorial47.py | 4 +--- docs/tutorial/src/tutorial48.py | 3 +-- docs/tutorial/src/tutorial49.py | 5 ++--- docs/tutorial/src/tutorial50.py | 9 ++++++--- docs/tutorial/src/tutorial51.py | 5 +---- docs/tutorial/src/tutorial52.py | 5 +---- docs/tutorial/src/tutorial53.py | 5 +---- docs/tutorial/src/tutorial54.py | 8 ++++---- docs/tutorial/src/tutorial55.py | 7 +++---- docs/tutorial/src/tutorial56.py | 7 +++---- docs/tutorial/src/tutorial57.py | 7 +++---- docs/tutorial/src/tutorial58.py | 14 +++++++++----- docs/tutorial/src/tutorial59.py | 7 +------ docs/tutorial/src/tutorial60.py | 7 +------ docs/tutorial/src/tutorial61.py | 7 +------ docs/tutorial/src/tutorial62.py | 7 +------ docs/tutorial/src/tutorial63.py | 7 +------ docs/tutorial/src/tutorial64.py | 9 ++------- docs/tutorial/src/tutorial65.py | 11 +++++------ docs/tutorial/src/tutorial66.py | 17 +++++++++-------- docs/tutorial/src/tutorial67.py | 17 +++++------------ docs/tutorial/src/tutorial68.py | 15 +++------------ 60 files changed, 165 insertions(+), 233 deletions(-) diff --git a/docs/tutorial/src/tutorial01.py b/docs/tutorial/src/tutorial01.py index 2a268787c..ee60be1f9 100644 --- a/docs/tutorial/src/tutorial01.py +++ b/docs/tutorial/src/tutorial01.py @@ -2,6 +2,7 @@ from fastapi import FastAPI app = FastAPI() + @app.get("/") async def root(): return {"message": "Hello World"} diff --git a/docs/tutorial/src/tutorial02.py b/docs/tutorial/src/tutorial02.py index 82de3e6b3..7bbf70e6c 100644 --- a/docs/tutorial/src/tutorial02.py +++ b/docs/tutorial/src/tutorial02.py @@ -2,6 +2,7 @@ from fastapi import FastAPI app = FastAPI() + @app.get("/items/{item_id}") async def read_item(item_id): return {"item_id": item_id} diff --git a/docs/tutorial/src/tutorial03.py b/docs/tutorial/src/tutorial03.py index 9f76dd159..8272ad70d 100644 --- a/docs/tutorial/src/tutorial03.py +++ b/docs/tutorial/src/tutorial03.py @@ -2,6 +2,7 @@ from fastapi import FastAPI app = FastAPI() + @app.get("/items/{item_id}") async def read_item(item_id: int): return {"item_id": item_id} diff --git a/docs/tutorial/src/tutorial04.py b/docs/tutorial/src/tutorial04.py index 3e81155af..ba67bb6f9 100644 --- a/docs/tutorial/src/tutorial04.py +++ b/docs/tutorial/src/tutorial04.py @@ -1,8 +1,10 @@ -from fastapi import FastAPI from uuid import UUID +from fastapi import FastAPI + app = FastAPI() + @app.get("/items/{item_id}") async def read_item(item_id: UUID): return {"item_id": item_id} diff --git a/docs/tutorial/src/tutorial05.py b/docs/tutorial/src/tutorial05.py index b446ba4b9..690c35461 100644 --- a/docs/tutorial/src/tutorial05.py +++ b/docs/tutorial/src/tutorial05.py @@ -2,11 +2,8 @@ from fastapi import FastAPI app = FastAPI() -fake_items_db = [ - {"item_name": "Foo"}, - {"item_name": "Bar"}, - {"item_name": "Baz"}, -] +fake_items_db = [{"item_name": "Foo"}, {"item_name": "Bar"}, {"item_name": "Baz"}] + @app.get("/items/") async def read_item(skip: int = 0, limit: int = 100): diff --git a/docs/tutorial/src/tutorial06.py b/docs/tutorial/src/tutorial06.py index 54191b66a..6e9348817 100644 --- a/docs/tutorial/src/tutorial06.py +++ b/docs/tutorial/src/tutorial06.py @@ -1,8 +1,8 @@ from fastapi import FastAPI -from fastapi import FastAPI app = FastAPI() + @app.get("/items/{item_id}") async def read_item(item_id: str, q: str = None): if q: diff --git a/docs/tutorial/src/tutorial07.py b/docs/tutorial/src/tutorial07.py index 30f0cd6d5..bba18c410 100644 --- a/docs/tutorial/src/tutorial07.py +++ b/docs/tutorial/src/tutorial07.py @@ -2,11 +2,14 @@ from fastapi import FastAPI app = FastAPI() + @app.get("/items/{item_id}") async def read_item(item_id: str, q: str = None, short: bool = False): item = {"item_id": item_id} if q: item.update({"q": q}) if not short: - item.update({"description": "This is an amazing item that has a long description"}) + item.update( + {"description": "This is an amazing item that has a long description"} + ) return item diff --git a/docs/tutorial/src/tutorial08.py b/docs/tutorial/src/tutorial08.py index d45ebba9f..4407baf9a 100644 --- a/docs/tutorial/src/tutorial08.py +++ b/docs/tutorial/src/tutorial08.py @@ -2,11 +2,16 @@ from fastapi import FastAPI app = FastAPI() + @app.get("/users/{user_id}/items/{item_id}") -async def read_user_item(user_id: int, item_id: str, q: str = None, short: bool = False): +async def read_user_item( + user_id: int, item_id: str, q: str = None, short: bool = False +): item = {"item_id": item_id, "owner_id": user_id} if q: item.update({"q": q}) if not short: - item.update({"description": "This is an amazing item that has a long description"}) + item.update( + {"description": "This is an amazing item that has a long description"} + ) return item diff --git a/docs/tutorial/src/tutorial09.py b/docs/tutorial/src/tutorial09.py index c0b122793..125bce9c5 100644 --- a/docs/tutorial/src/tutorial09.py +++ b/docs/tutorial/src/tutorial09.py @@ -2,11 +2,16 @@ from fastapi import FastAPI app = FastAPI() + @app.get("/users/{user_id}/items/{item_id}") -async def read_user_item(user_id: int, item_id: str, needy: str, q: str = None, short: bool = False): +async def read_user_item( + user_id: int, item_id: str, needy: str, q: str = None, short: bool = False +): item = {"item_id": item_id, "owner_id": user_id, "needy": needy} if q: item.update({"q": q}) if not short: - item.update({"description": "This is an amazing item that has a long description"}) + item.update( + {"description": "This is an amazing item that has a long description"} + ) return item diff --git a/docs/tutorial/src/tutorial10.py b/docs/tutorial/src/tutorial10.py index 78b813f52..e99a46ccc 100644 --- a/docs/tutorial/src/tutorial10.py +++ b/docs/tutorial/src/tutorial10.py @@ -1,6 +1,7 @@ from fastapi import FastAPI from pydantic import BaseModel + class Item(BaseModel): name: str description: str = None @@ -10,6 +11,7 @@ class Item(BaseModel): app = FastAPI() + @app.post("/items/") async def create_item(item: Item): return item diff --git a/docs/tutorial/src/tutorial11.py b/docs/tutorial/src/tutorial11.py index 925f11062..cce5eca49 100644 --- a/docs/tutorial/src/tutorial11.py +++ b/docs/tutorial/src/tutorial11.py @@ -1,6 +1,7 @@ from fastapi import FastAPI from pydantic import BaseModel + class Item(BaseModel): name: str description: str = None @@ -10,6 +11,7 @@ class Item(BaseModel): app = FastAPI() + @app.post("/items/") async def create_item(item: Item): item_dict = item.dict() diff --git a/docs/tutorial/src/tutorial12.py b/docs/tutorial/src/tutorial12.py index 34e9849a1..1d3e90240 100644 --- a/docs/tutorial/src/tutorial12.py +++ b/docs/tutorial/src/tutorial12.py @@ -1,6 +1,7 @@ from fastapi import FastAPI from pydantic import BaseModel + class Item(BaseModel): name: str description: str = None @@ -10,6 +11,7 @@ class Item(BaseModel): app = FastAPI() + @app.put("/items/{item_id}") async def create_item(item_id: int, item: Item): return {"item_id": item_id, **item.dict()} diff --git a/docs/tutorial/src/tutorial13.py b/docs/tutorial/src/tutorial13.py index be6239d8f..c389af241 100644 --- a/docs/tutorial/src/tutorial13.py +++ b/docs/tutorial/src/tutorial13.py @@ -1,6 +1,7 @@ from fastapi import FastAPI from pydantic import BaseModel + class Item(BaseModel): name: str description: str = None @@ -10,6 +11,7 @@ class Item(BaseModel): app = FastAPI() + @app.put("/items/{item_id}") async def create_item(item_id: int, item: Item, q: str = None): result = {"item_id": item_id, **item.dict()} diff --git a/docs/tutorial/src/tutorial16.py b/docs/tutorial/src/tutorial16.py index bdaf5c1a4..785db44c0 100644 --- a/docs/tutorial/src/tutorial16.py +++ b/docs/tutorial/src/tutorial16.py @@ -4,7 +4,9 @@ app = FastAPI() @app.get("/items/") -async def read_items(q: str = Query(None, min_length=3, max_length=50, regex="^fixedquery$")): +async def read_items( + q: str = Query(None, min_length=3, max_length=50, regex="^fixedquery$") +): results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]} if q: results.update({"q": q}) diff --git a/docs/tutorial/src/tutorial23.py b/docs/tutorial/src/tutorial23.py index 0600c7f83..fc1911872 100644 --- a/docs/tutorial/src/tutorial23.py +++ b/docs/tutorial/src/tutorial23.py @@ -1,4 +1,4 @@ -from fastapi import FastAPI, Query, Path +from fastapi import FastAPI, Path, Query app = FastAPI() diff --git a/docs/tutorial/src/tutorial24.py b/docs/tutorial/src/tutorial24.py index c14950716..57ca50ece 100644 --- a/docs/tutorial/src/tutorial24.py +++ b/docs/tutorial/src/tutorial24.py @@ -1,12 +1,11 @@ -from fastapi import FastAPI, Query, Path +from fastapi import FastAPI, Path app = FastAPI() @app.get("/items/{item_id}") async def read_items( - q: str, - item_id: int = Path(..., title="The ID of the item to get"), + q: str, item_id: int = Path(..., title="The ID of the item to get") ): results = {"item_id": item_id} if q: diff --git a/docs/tutorial/src/tutorial25.py b/docs/tutorial/src/tutorial25.py index 4ac37c409..b6b5a1986 100644 --- a/docs/tutorial/src/tutorial25.py +++ b/docs/tutorial/src/tutorial25.py @@ -1,13 +1,11 @@ -from fastapi import FastAPI, Query, Path +from fastapi import FastAPI, Path app = FastAPI() @app.get("/items/{item_id}") async def read_items( - *, - item_id: int = Path(..., title="The ID of the item to get"), - q: str, + *, item_id: int = Path(..., title="The ID of the item to get"), q: str ): results = {"item_id": item_id} if q: diff --git a/docs/tutorial/src/tutorial26.py b/docs/tutorial/src/tutorial26.py index 97611c273..2ec708280 100644 --- a/docs/tutorial/src/tutorial26.py +++ b/docs/tutorial/src/tutorial26.py @@ -1,13 +1,11 @@ -from fastapi import FastAPI, Query, Path +from fastapi import FastAPI, Path app = FastAPI() @app.get("/items/{item_id}") async def read_items( - *, - item_id: int = Path(..., title="The ID of the item to get", ge=1), - q: str, + *, item_id: int = Path(..., title="The ID of the item to get", ge=1), q: str ): results = {"item_id": item_id} if q: diff --git a/docs/tutorial/src/tutorial27.py b/docs/tutorial/src/tutorial27.py index 4dabe3537..2809f37b2 100644 --- a/docs/tutorial/src/tutorial27.py +++ b/docs/tutorial/src/tutorial27.py @@ -1,4 +1,4 @@ -from fastapi import FastAPI, Query, Path +from fastapi import FastAPI, Path app = FastAPI() diff --git a/docs/tutorial/src/tutorial28.py b/docs/tutorial/src/tutorial28.py index 72b2bba1f..0c19579f5 100644 --- a/docs/tutorial/src/tutorial28.py +++ b/docs/tutorial/src/tutorial28.py @@ -1,4 +1,4 @@ -from fastapi import FastAPI, Query, Path +from fastapi import FastAPI, Path, Query app = FastAPI() diff --git a/docs/tutorial/src/tutorial29.py b/docs/tutorial/src/tutorial29.py index 00836004e..7918a2f96 100644 --- a/docs/tutorial/src/tutorial29.py +++ b/docs/tutorial/src/tutorial29.py @@ -1,4 +1,4 @@ -from fastapi import FastAPI, Query, Path +from fastapi import FastAPI, Path from pydantic import BaseModel app = FastAPI() diff --git a/docs/tutorial/src/tutorial30.py b/docs/tutorial/src/tutorial30.py index 31dbb82c9..5c9e8344d 100644 --- a/docs/tutorial/src/tutorial30.py +++ b/docs/tutorial/src/tutorial30.py @@ -1,4 +1,4 @@ -from fastapi import FastAPI, Query, Path +from fastapi import FastAPI from pydantic import BaseModel app = FastAPI() @@ -17,11 +17,6 @@ class User(BaseModel): @app.put("/items/{item_id}") -async def update_item( - *, - item_id: int, - item: Item, - user: User, -): +async def update_item(*, item_id: int, item: Item, user: User): results = {"item_id": item_id, "item": item, "user": user} return results diff --git a/docs/tutorial/src/tutorial31.py b/docs/tutorial/src/tutorial31.py index a1302229b..8dae852a5 100644 --- a/docs/tutorial/src/tutorial31.py +++ b/docs/tutorial/src/tutorial31.py @@ -1,4 +1,4 @@ -from fastapi import FastAPI, Query, Path, Body +from fastapi import Body, FastAPI from pydantic import BaseModel app = FastAPI() @@ -18,11 +18,12 @@ class User(BaseModel): @app.put("/items/{item_id}") async def update_item( - *, - item_id: int, - item: Item, - user: User, - access_token: str = Body(...), + *, item_id: int, item: Item, user: User, access_token: str = Body(...) ): - results = {"item_id": item_id, "item": item, "user": user, "access_token": access_token} + results = { + "item_id": item_id, + "item": item, + "user": user, + "access_token": access_token, + } return results diff --git a/docs/tutorial/src/tutorial32.py b/docs/tutorial/src/tutorial32.py index 584451ed4..845618fdf 100644 --- a/docs/tutorial/src/tutorial32.py +++ b/docs/tutorial/src/tutorial32.py @@ -1,4 +1,4 @@ -from fastapi import FastAPI, Query, Path, Body +from fastapi import Body, FastAPI from pydantic import BaseModel app = FastAPI() @@ -25,7 +25,12 @@ async def update_item( access_token: str = Body(...), q: str = None, ): - results = {"item_id": item_id, "item": item, "user": user, "access_token": access_token} + results = { + "item_id": item_id, + "item": item, + "user": user, + "access_token": access_token, + } if q: results.update({"q": q}) return results diff --git a/docs/tutorial/src/tutorial33.py b/docs/tutorial/src/tutorial33.py index 559356f99..61f1b2917 100644 --- a/docs/tutorial/src/tutorial33.py +++ b/docs/tutorial/src/tutorial33.py @@ -1,4 +1,4 @@ -from fastapi import FastAPI, Query, Path, Body +from fastapi import Body, FastAPI from pydantic import BaseModel app = FastAPI() @@ -12,10 +12,6 @@ class Item(BaseModel): @app.put("/items/{item_id}") -async def update_item( - *, - item_id: int, - item: Item = Body(..., embed=True), -): +async def update_item(*, item_id: int, item: Item = Body(..., embed=True)): results = {"item_id": item_id, "item": item} return results diff --git a/docs/tutorial/src/tutorial34.py b/docs/tutorial/src/tutorial34.py index 89b97e8c8..6c8b101ba 100644 --- a/docs/tutorial/src/tutorial34.py +++ b/docs/tutorial/src/tutorial34.py @@ -1,4 +1,4 @@ -from fastapi import FastAPI, Query, Path, Body +from fastapi import Body, FastAPI from pydantic import BaseModel, Schema app = FastAPI() @@ -12,10 +12,6 @@ class Item(BaseModel): @app.put("/items/{item_id}") -async def update_item( - *, - item_id: int, - item: Item = Body(..., embed=True), -): +async def update_item(*, item_id: int, item: Item = Body(..., embed=True)): results = {"item_id": item_id, "item": item} return results diff --git a/docs/tutorial/src/tutorial35.py b/docs/tutorial/src/tutorial35.py index e6fa5843a..9e0fa4494 100644 --- a/docs/tutorial/src/tutorial35.py +++ b/docs/tutorial/src/tutorial35.py @@ -1,4 +1,4 @@ -from fastapi import FastAPI, Query, Path, Body +from fastapi import FastAPI from pydantic import BaseModel app = FastAPI() @@ -13,10 +13,6 @@ class Item(BaseModel): @app.put("/items/{item_id}") -async def update_item( - *, - item_id: int, - item: Item, -): +async def update_item(*, item_id: int, item: Item): results = {"item_id": item_id, "item": item} return results diff --git a/docs/tutorial/src/tutorial36.py b/docs/tutorial/src/tutorial36.py index 652ec7c57..8f769279b 100644 --- a/docs/tutorial/src/tutorial36.py +++ b/docs/tutorial/src/tutorial36.py @@ -1,7 +1,8 @@ -from fastapi import Body, FastAPI, Path, Query -from pydantic import BaseModel from typing import List +from fastapi import FastAPI +from pydantic import BaseModel + app = FastAPI() @@ -14,10 +15,6 @@ class Item(BaseModel): @app.put("/items/{item_id}") -async def update_item( - *, - item_id: int, - item: Item, -): +async def update_item(*, item_id: int, item: Item): results = {"item_id": item_id, "item": item} return results diff --git a/docs/tutorial/src/tutorial37.py b/docs/tutorial/src/tutorial37.py index 444f73ac5..291b3c64d 100644 --- a/docs/tutorial/src/tutorial37.py +++ b/docs/tutorial/src/tutorial37.py @@ -1,7 +1,8 @@ -from fastapi import Body, FastAPI, Path, Query -from pydantic import BaseModel from typing import Set +from fastapi import FastAPI +from pydantic import BaseModel + app = FastAPI() @@ -14,10 +15,6 @@ class Item(BaseModel): @app.put("/items/{item_id}") -async def update_item( - *, - item_id: int, - item: Item, -): +async def update_item(*, item_id: int, item: Item): results = {"item_id": item_id, "item": item} return results diff --git a/docs/tutorial/src/tutorial38.py b/docs/tutorial/src/tutorial38.py index 6cfbeff39..257928ef3 100644 --- a/docs/tutorial/src/tutorial38.py +++ b/docs/tutorial/src/tutorial38.py @@ -1,7 +1,8 @@ -from fastapi import Body, FastAPI, Path, Query -from pydantic import BaseModel from typing import Set +from fastapi import FastAPI +from pydantic import BaseModel + app = FastAPI() @@ -20,10 +21,6 @@ class Item(BaseModel): @app.put("/items/{item_id}") -async def update_item( - *, - item_id: int, - item: Item, -): +async def update_item(*, item_id: int, item: Item): results = {"item_id": item_id, "item": item} return results diff --git a/docs/tutorial/src/tutorial39.py b/docs/tutorial/src/tutorial39.py index d04e72d80..f5f19b390 100644 --- a/docs/tutorial/src/tutorial39.py +++ b/docs/tutorial/src/tutorial39.py @@ -1,7 +1,8 @@ -from fastapi import Body, FastAPI, Path, Query +from typing import Set + +from fastapi import FastAPI from pydantic import BaseModel from pydantic.types import UrlStr -from typing import Set app = FastAPI() @@ -21,10 +22,6 @@ class Item(BaseModel): @app.put("/items/{item_id}") -async def update_item( - *, - item_id: int, - item: Item, -): +async def update_item(*, item_id: int, item: Item): results = {"item_id": item_id, "item": item} return results diff --git a/docs/tutorial/src/tutorial40.py b/docs/tutorial/src/tutorial40.py index e5c25e4b6..09d8be768 100644 --- a/docs/tutorial/src/tutorial40.py +++ b/docs/tutorial/src/tutorial40.py @@ -1,7 +1,8 @@ -from fastapi import Body, FastAPI, Path, Query +from typing import List, Set + +from fastapi import FastAPI from pydantic import BaseModel from pydantic.types import UrlStr -from typing import Set, List app = FastAPI() @@ -21,10 +22,6 @@ class Item(BaseModel): @app.put("/items/{item_id}") -async def update_item( - *, - item_id: int, - item: Item, -): +async def update_item(*, item_id: int, item: Item): results = {"item_id": item_id, "item": item} return results diff --git a/docs/tutorial/src/tutorial41.py b/docs/tutorial/src/tutorial41.py index 3dd1a0554..cda802d3e 100644 --- a/docs/tutorial/src/tutorial41.py +++ b/docs/tutorial/src/tutorial41.py @@ -1,7 +1,8 @@ -from fastapi import Body, FastAPI, Path, Query +from typing import List, Set + +from fastapi import FastAPI from pydantic import BaseModel from pydantic.types import UrlStr -from typing import Set, List app = FastAPI() diff --git a/docs/tutorial/src/tutorial42.py b/docs/tutorial/src/tutorial42.py index b57a243d7..34b868563 100644 --- a/docs/tutorial/src/tutorial42.py +++ b/docs/tutorial/src/tutorial42.py @@ -1,7 +1,8 @@ -from fastapi import Body, FastAPI, Path, Query +from typing import List + +from fastapi import FastAPI from pydantic import BaseModel from pydantic.types import UrlStr -from typing import Set, List app = FastAPI() diff --git a/docs/tutorial/src/tutorial43.py b/docs/tutorial/src/tutorial43.py index f1cc8b2c6..5a6fd30fe 100644 --- a/docs/tutorial/src/tutorial43.py +++ b/docs/tutorial/src/tutorial43.py @@ -1,7 +1,4 @@ -from fastapi import FastAPI, Cookie -from pydantic import BaseModel -from pydantic.types import UrlStr -from typing import Set, List +from fastapi import Cookie, FastAPI app = FastAPI() diff --git a/docs/tutorial/src/tutorial44.py b/docs/tutorial/src/tutorial44.py index 9dbb9912c..24a59e530 100644 --- a/docs/tutorial/src/tutorial44.py +++ b/docs/tutorial/src/tutorial44.py @@ -1,7 +1,4 @@ from fastapi import FastAPI, Header -from pydantic import BaseModel -from pydantic.types import UrlStr -from typing import Set, List app = FastAPI() diff --git a/docs/tutorial/src/tutorial45.py b/docs/tutorial/src/tutorial45.py index 070c7fe51..4edc4b6fd 100644 --- a/docs/tutorial/src/tutorial45.py +++ b/docs/tutorial/src/tutorial45.py @@ -1,7 +1,4 @@ from fastapi import FastAPI, Header -from pydantic import BaseModel -from pydantic.types import UrlStr -from typing import Set, List app = FastAPI() diff --git a/docs/tutorial/src/tutorial46.py b/docs/tutorial/src/tutorial46.py index e89278270..86dadcbda 100644 --- a/docs/tutorial/src/tutorial46.py +++ b/docs/tutorial/src/tutorial46.py @@ -1,7 +1,7 @@ -from fastapi import Body, FastAPI, Path, Query +from typing import Set + +from fastapi import FastAPI from pydantic import BaseModel -from pydantic.types import UrlStr -from typing import Set, List app = FastAPI() diff --git a/docs/tutorial/src/tutorial47.py b/docs/tutorial/src/tutorial47.py index 5ec7fa4aa..3fb475b9d 100644 --- a/docs/tutorial/src/tutorial47.py +++ b/docs/tutorial/src/tutorial47.py @@ -1,7 +1,6 @@ -from fastapi import Body, FastAPI, Path, Query +from fastapi import FastAPI from pydantic import BaseModel from pydantic.types import EmailStr -from typing import Set, List app = FastAPI() @@ -11,7 +10,6 @@ class UserIn(BaseModel): password: str email: EmailStr full_name: str = None - # Don't do this in production! diff --git a/docs/tutorial/src/tutorial48.py b/docs/tutorial/src/tutorial48.py index d9cdd86d5..c8ea361d8 100644 --- a/docs/tutorial/src/tutorial48.py +++ b/docs/tutorial/src/tutorial48.py @@ -1,7 +1,6 @@ -from fastapi import Body, FastAPI, Path, Query +from fastapi import FastAPI from pydantic import BaseModel from pydantic.types import EmailStr -from typing import Set, List app = FastAPI() diff --git a/docs/tutorial/src/tutorial49.py b/docs/tutorial/src/tutorial49.py index c2811eba0..aa8e7dad4 100644 --- a/docs/tutorial/src/tutorial49.py +++ b/docs/tutorial/src/tutorial49.py @@ -1,8 +1,6 @@ -from fastapi import Body, FastAPI, Path, Query +from fastapi import FastAPI from pydantic import BaseModel from pydantic.types import EmailStr -from typing import Set, List -from uuid import UUID, uuid4 app = FastAPI() @@ -37,6 +35,7 @@ def fake_save_user(user_in: UserIn): print("User saved! ..not really") return user_in_db + @app.post("/user/", response_model=UserOut) async def create_user(*, user_in: UserIn): user_saved = fake_save_user(user_in) diff --git a/docs/tutorial/src/tutorial50.py b/docs/tutorial/src/tutorial50.py index b61e62b83..605baf91f 100644 --- a/docs/tutorial/src/tutorial50.py +++ b/docs/tutorial/src/tutorial50.py @@ -1,15 +1,16 @@ -from fastapi import Body, FastAPI, Path, Query +from fastapi import FastAPI from pydantic import BaseModel from pydantic.types import EmailStr -from typing import Set, List app = FastAPI() + class UserBase(BaseModel): username: str email: EmailStr full_name: str = None + class UserIn(UserBase): password: str @@ -17,9 +18,10 @@ class UserIn(UserBase): class UserOut(UserBase): pass + class UserInDB(UserBase): hashed_password: str - + def fake_password_hasher(raw_password: str): return "supersecret" + raw_password @@ -31,6 +33,7 @@ def fake_save_user(user_in: UserIn): print("User saved! ..not really") return user_in_db + @app.post("/user/", response_model=UserOut) async def create_user(*, user_in: UserIn): user_saved = fake_save_user(user_in) diff --git a/docs/tutorial/src/tutorial51.py b/docs/tutorial/src/tutorial51.py index 52a93d7ff..0290b644d 100644 --- a/docs/tutorial/src/tutorial51.py +++ b/docs/tutorial/src/tutorial51.py @@ -1,7 +1,4 @@ -from fastapi import Body, FastAPI, Path, Query, Form -from pydantic import BaseModel -from pydantic.types import EmailStr -from typing import Set, List +from fastapi import FastAPI, Form app = FastAPI() diff --git a/docs/tutorial/src/tutorial52.py b/docs/tutorial/src/tutorial52.py index 3a517f7a1..3e99fcdde 100644 --- a/docs/tutorial/src/tutorial52.py +++ b/docs/tutorial/src/tutorial52.py @@ -1,7 +1,4 @@ -from fastapi import Body, FastAPI, Path, Query, File -from pydantic import BaseModel -from pydantic.types import EmailStr -from typing import Set, List +from fastapi import FastAPI, File app = FastAPI() diff --git a/docs/tutorial/src/tutorial53.py b/docs/tutorial/src/tutorial53.py index 19382b815..1882a6397 100644 --- a/docs/tutorial/src/tutorial53.py +++ b/docs/tutorial/src/tutorial53.py @@ -1,7 +1,4 @@ -from fastapi import Body, FastAPI, Path, Query, File, Form -from pydantic import BaseModel -from pydantic.types import EmailStr -from typing import Set, List +from fastapi import FastAPI, File, Form app = FastAPI() diff --git a/docs/tutorial/src/tutorial54.py b/docs/tutorial/src/tutorial54.py index fb32535c2..b48601867 100644 --- a/docs/tutorial/src/tutorial54.py +++ b/docs/tutorial/src/tutorial54.py @@ -1,8 +1,8 @@ -from fastapi import Body, FastAPI, Path, Query -from starlette.status import HTTP_201_CREATED +from typing import Set + +from fastapi import FastAPI from pydantic import BaseModel -from pydantic.types import UrlStr -from typing import Set, List +from starlette.status import HTTP_201_CREATED app = FastAPI() diff --git a/docs/tutorial/src/tutorial55.py b/docs/tutorial/src/tutorial55.py index bd0bef7f9..ccd5437da 100644 --- a/docs/tutorial/src/tutorial55.py +++ b/docs/tutorial/src/tutorial55.py @@ -1,8 +1,7 @@ -from fastapi import Body, FastAPI, Path, Query -from starlette.status import HTTP_201_CREATED +from typing import Set + +from fastapi import FastAPI from pydantic import BaseModel -from pydantic.types import UrlStr -from typing import Set, List app = FastAPI() diff --git a/docs/tutorial/src/tutorial56.py b/docs/tutorial/src/tutorial56.py index 8a163389d..106607fd2 100644 --- a/docs/tutorial/src/tutorial56.py +++ b/docs/tutorial/src/tutorial56.py @@ -1,8 +1,7 @@ -from fastapi import Body, FastAPI, Path, Query -from starlette.status import HTTP_201_CREATED +from typing import Set + +from fastapi import FastAPI from pydantic import BaseModel -from pydantic.types import UrlStr -from typing import Set, List app = FastAPI() diff --git a/docs/tutorial/src/tutorial57.py b/docs/tutorial/src/tutorial57.py index 479ac7d58..a4151a8cd 100644 --- a/docs/tutorial/src/tutorial57.py +++ b/docs/tutorial/src/tutorial57.py @@ -1,8 +1,7 @@ -from fastapi import Body, FastAPI, Path, Query -from starlette.status import HTTP_201_CREATED +from typing import Set + +from fastapi import FastAPI from pydantic import BaseModel -from pydantic.types import UrlStr -from typing import Set, List app = FastAPI() diff --git a/docs/tutorial/src/tutorial58.py b/docs/tutorial/src/tutorial58.py index bec8a6ad2..f710e6c66 100644 --- a/docs/tutorial/src/tutorial58.py +++ b/docs/tutorial/src/tutorial58.py @@ -1,8 +1,7 @@ -from fastapi import Body, FastAPI, Path, Query -from starlette.status import HTTP_201_CREATED +from typing import Set + +from fastapi import FastAPI from pydantic import BaseModel -from pydantic.types import UrlStr -from typing import Set, List app = FastAPI() @@ -15,7 +14,12 @@ class Item(BaseModel): tags: Set[str] = [] -@app.post("/items/", response_model=Item, summary="Create an item", response_description="The created item") +@app.post( + "/items/", + response_model=Item, + summary="Create an item", + response_description="The created item", +) async def create_item(*, item: Item): """ Create an item with all the information: diff --git a/docs/tutorial/src/tutorial59.py b/docs/tutorial/src/tutorial59.py index 1a77be023..11f3de6db 100644 --- a/docs/tutorial/src/tutorial59.py +++ b/docs/tutorial/src/tutorial59.py @@ -1,9 +1,4 @@ -from typing import List, Set - -from fastapi import Body, FastAPI, Path, Query -from pydantic import BaseModel -from pydantic.types import UrlStr -from starlette.status import HTTP_201_CREATED +from fastapi import FastAPI app = FastAPI() diff --git a/docs/tutorial/src/tutorial60.py b/docs/tutorial/src/tutorial60.py index 31793c985..fafa8ffb8 100644 --- a/docs/tutorial/src/tutorial60.py +++ b/docs/tutorial/src/tutorial60.py @@ -1,9 +1,4 @@ -from typing import List, Set - -from fastapi import Body, FastAPI, Path, Query -from pydantic import BaseModel -from pydantic.types import UrlStr -from starlette.status import HTTP_201_CREATED +from fastapi import FastAPI app = FastAPI() diff --git a/docs/tutorial/src/tutorial61.py b/docs/tutorial/src/tutorial61.py index 34f9e8563..dcc358e32 100644 --- a/docs/tutorial/src/tutorial61.py +++ b/docs/tutorial/src/tutorial61.py @@ -1,9 +1,4 @@ -from typing import List, Set - -from fastapi import Body, FastAPI, Path, Query -from pydantic import BaseModel -from pydantic.types import UrlStr -from starlette.status import HTTP_201_CREATED +from fastapi import FastAPI app = FastAPI() diff --git a/docs/tutorial/src/tutorial62.py b/docs/tutorial/src/tutorial62.py index dec2f53e2..bba3f342d 100644 --- a/docs/tutorial/src/tutorial62.py +++ b/docs/tutorial/src/tutorial62.py @@ -1,9 +1,4 @@ -from typing import List, Set - -from fastapi import Body, FastAPI, Path, Query -from pydantic import BaseModel -from pydantic.types import UrlStr -from starlette.status import HTTP_201_CREATED +from fastapi import FastAPI from starlette.responses import UJSONResponse app = FastAPI() diff --git a/docs/tutorial/src/tutorial63.py b/docs/tutorial/src/tutorial63.py index f2300f8d4..214e64263 100644 --- a/docs/tutorial/src/tutorial63.py +++ b/docs/tutorial/src/tutorial63.py @@ -1,9 +1,4 @@ -from typing import List, Set - -from fastapi import Body, FastAPI, Path, Query -from pydantic import BaseModel -from pydantic.types import UrlStr -from starlette.status import HTTP_201_CREATED +from fastapi import FastAPI from starlette.responses import HTMLResponse app = FastAPI() diff --git a/docs/tutorial/src/tutorial64.py b/docs/tutorial/src/tutorial64.py index 9fe0da7b1..82a51634e 100644 --- a/docs/tutorial/src/tutorial64.py +++ b/docs/tutorial/src/tutorial64.py @@ -1,10 +1,5 @@ -from typing import List, Set - -from fastapi import Body, FastAPI, Path, Query, Depends +from fastapi import Depends, FastAPI from pydantic import BaseModel -from pydantic.types import UrlStr -from starlette.status import HTTP_201_CREATED -from starlette.responses import HTMLResponse app = FastAPI() @@ -27,6 +22,6 @@ async def read_items(commons: CommonQueryParams = Depends(common_parameters)): response = {} if commons.q: response.update({"q": commons.q}) - items = fake_items_db[commons.skip:commons.limit] + items = fake_items_db[commons.skip : commons.limit] response.update({"items": items}) return response diff --git a/docs/tutorial/src/tutorial65.py b/docs/tutorial/src/tutorial65.py index 41a63c420..e015f9585 100644 --- a/docs/tutorial/src/tutorial65.py +++ b/docs/tutorial/src/tutorial65.py @@ -1,10 +1,7 @@ -from typing import List, Set +from typing import List -from fastapi import Body, FastAPI, Path, Query, Depends, Cookie +from fastapi import Cookie, Depends, FastAPI from pydantic import BaseModel -from pydantic.types import UrlStr -from starlette.status import HTTP_201_CREATED -from starlette.responses import HTMLResponse app = FastAPI() @@ -30,6 +27,8 @@ async def get_tracked_interests(track_code: str = Cookie(None)): @app.get("/interests/") -async def read_interests(tracked_interests: InterestsTracker = Depends(get_tracked_interests)): +async def read_interests( + tracked_interests: InterestsTracker = Depends(get_tracked_interests) +): response = {"interests": tracked_interests.interests} return response diff --git a/docs/tutorial/src/tutorial66.py b/docs/tutorial/src/tutorial66.py index 310420686..3697b170a 100644 --- a/docs/tutorial/src/tutorial66.py +++ b/docs/tutorial/src/tutorial66.py @@ -1,11 +1,8 @@ -from typing import List, Set +from random import choice +from typing import List -from fastapi import Body, FastAPI, Path, Query, Depends, Cookie +from fastapi import Cookie, Depends, FastAPI from pydantic import BaseModel -from pydantic.types import UrlStr -from starlette.status import HTTP_201_CREATED -from starlette.responses import HTMLResponse -from random import choice app = FastAPI() @@ -21,6 +18,7 @@ fake_tracked_users_db = { "Baz": {"track_code": "Baz", "interests": ["gaming", "virtual reality"]}, } + async def get_tracked_interests(track_code: str = Cookie(None)): if track_code in fake_tracked_users_db: track_dict = fake_tracked_users_db[track_code] @@ -28,10 +26,11 @@ async def get_tracked_interests(track_code: str = Cookie(None)): return track return None + class ComplexTracker: def __init__(self, tracker: InterestsTracker = Depends(get_tracked_interests)): self.tracker = tracker - + def random_interest(self): """ Get a random interest from the tracked ones for the current user. @@ -39,7 +38,9 @@ class ComplexTracker: """ if self.tracker.interests: return choice(self.tracker.interests) - return choice(["sports", "movies", "food", "shows", "gaming", "virtual reality"]) + return choice( + ["sports", "movies", "food", "shows", "gaming", "virtual reality"] + ) @app.get("/suggested-category") diff --git a/docs/tutorial/src/tutorial67.py b/docs/tutorial/src/tutorial67.py index 442a93d17..720604c02 100644 --- a/docs/tutorial/src/tutorial67.py +++ b/docs/tutorial/src/tutorial67.py @@ -1,17 +1,8 @@ -from typing import List, Set +from fastapi import FastAPI -from fastapi import Body, FastAPI, Path, Query, Depends, Cookie -from pydantic import BaseModel -from pydantic.types import UrlStr -from starlette.status import HTTP_201_CREATED -from starlette.responses import HTMLResponse -from random import choice - -from sqlalchemy import create_engine -from sqlalchemy.orm import scoped_session, sessionmaker -from sqlalchemy import Column, Integer, DateTime, String, Boolean, ForeignKey +from sqlalchemy import Boolean, Column, Integer, String, create_engine from sqlalchemy.ext.declarative import declarative_base, declared_attr - +from sqlalchemy.orm import scoped_session, sessionmaker # SQLAlchemy specific code, as with any other app @@ -22,6 +13,7 @@ SQLALCHEMY_DATABASE_URI = "postgresql://user:password@postgresserver/db" # automatic __tablename__ attributes. So you don't have to declare them. # So, your models will behave very similarly to, for example, Flask-SQLAlchemy + class CustomBase: # Generate __tablename__ automatically @declared_attr @@ -49,6 +41,7 @@ db_session = scoped_session( def get_user(username, db_session): return db_session.query(User).filter(User.id == username).first() + # FastAPI specific code app = FastAPI() diff --git a/docs/tutorial/src/tutorial68.py b/docs/tutorial/src/tutorial68.py index 9725142ca..26897e1c9 100644 --- a/docs/tutorial/src/tutorial68.py +++ b/docs/tutorial/src/tutorial68.py @@ -1,21 +1,12 @@ -from typing import List, Set - -from fastapi import Body, FastAPI, Path, Query, Depends, Cookie -from pydantic import BaseModel -from pydantic.types import UrlStr -from starlette.status import HTTP_201_CREATED -from starlette.responses import HTMLResponse -from random import choice - -from typing import List, Optional, Union +from typing import Optional +from fastapi import FastAPI from pydantic import BaseModel from app.models.config import USERPROFILE_DOC_TYPE -from app.models.role import RoleEnum +from couchbase import LOCKMODE_WAIT from couchbase.bucket import Bucket from couchbase.cluster import Cluster, PasswordAuthenticator -from couchbase import LOCKMODE_WAIT def get_bucket():