Browse Source

🎨 Lint and format tutorial src files

pull/11/head
Sebastián Ramírez 6 years ago
parent
commit
b0d62b3410
  1. 1
      docs/tutorial/src/tutorial01.py
  2. 1
      docs/tutorial/src/tutorial02.py
  3. 1
      docs/tutorial/src/tutorial03.py
  4. 4
      docs/tutorial/src/tutorial04.py
  5. 7
      docs/tutorial/src/tutorial05.py
  6. 2
      docs/tutorial/src/tutorial06.py
  7. 5
      docs/tutorial/src/tutorial07.py
  8. 9
      docs/tutorial/src/tutorial08.py
  9. 9
      docs/tutorial/src/tutorial09.py
  10. 2
      docs/tutorial/src/tutorial10.py
  11. 2
      docs/tutorial/src/tutorial11.py
  12. 2
      docs/tutorial/src/tutorial12.py
  13. 2
      docs/tutorial/src/tutorial13.py
  14. 4
      docs/tutorial/src/tutorial16.py
  15. 2
      docs/tutorial/src/tutorial23.py
  16. 5
      docs/tutorial/src/tutorial24.py
  17. 6
      docs/tutorial/src/tutorial25.py
  18. 6
      docs/tutorial/src/tutorial26.py
  19. 2
      docs/tutorial/src/tutorial27.py
  20. 2
      docs/tutorial/src/tutorial28.py
  21. 2
      docs/tutorial/src/tutorial29.py
  22. 9
      docs/tutorial/src/tutorial30.py
  23. 15
      docs/tutorial/src/tutorial31.py
  24. 9
      docs/tutorial/src/tutorial32.py
  25. 8
      docs/tutorial/src/tutorial33.py
  26. 8
      docs/tutorial/src/tutorial34.py
  27. 8
      docs/tutorial/src/tutorial35.py
  28. 11
      docs/tutorial/src/tutorial36.py
  29. 11
      docs/tutorial/src/tutorial37.py
  30. 11
      docs/tutorial/src/tutorial38.py
  31. 11
      docs/tutorial/src/tutorial39.py
  32. 11
      docs/tutorial/src/tutorial40.py
  33. 5
      docs/tutorial/src/tutorial41.py
  34. 5
      docs/tutorial/src/tutorial42.py
  35. 5
      docs/tutorial/src/tutorial43.py
  36. 3
      docs/tutorial/src/tutorial44.py
  37. 3
      docs/tutorial/src/tutorial45.py
  38. 6
      docs/tutorial/src/tutorial46.py
  39. 4
      docs/tutorial/src/tutorial47.py
  40. 3
      docs/tutorial/src/tutorial48.py
  41. 5
      docs/tutorial/src/tutorial49.py
  42. 7
      docs/tutorial/src/tutorial50.py
  43. 5
      docs/tutorial/src/tutorial51.py
  44. 5
      docs/tutorial/src/tutorial52.py
  45. 5
      docs/tutorial/src/tutorial53.py
  46. 8
      docs/tutorial/src/tutorial54.py
  47. 7
      docs/tutorial/src/tutorial55.py
  48. 7
      docs/tutorial/src/tutorial56.py
  49. 7
      docs/tutorial/src/tutorial57.py
  50. 14
      docs/tutorial/src/tutorial58.py
  51. 7
      docs/tutorial/src/tutorial59.py
  52. 7
      docs/tutorial/src/tutorial60.py
  53. 7
      docs/tutorial/src/tutorial61.py
  54. 7
      docs/tutorial/src/tutorial62.py
  55. 7
      docs/tutorial/src/tutorial63.py
  56. 9
      docs/tutorial/src/tutorial64.py
  57. 11
      docs/tutorial/src/tutorial65.py
  58. 15
      docs/tutorial/src/tutorial66.py
  59. 17
      docs/tutorial/src/tutorial67.py
  60. 15
      docs/tutorial/src/tutorial68.py

1
docs/tutorial/src/tutorial01.py

@ -2,6 +2,7 @@ from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}

1
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}

1
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}

4
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}

7
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):

2
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:

5
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

9
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

9
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

2
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

2
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()

2
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()}

2
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()}

4
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})

2
docs/tutorial/src/tutorial23.py

@ -1,4 +1,4 @@
from fastapi import FastAPI, Query, Path
from fastapi import FastAPI, Path, Query
app = FastAPI()

5
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:

6
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:

6
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:

2
docs/tutorial/src/tutorial27.py

@ -1,4 +1,4 @@
from fastapi import FastAPI, Query, Path
from fastapi import FastAPI, Path
app = FastAPI()

2
docs/tutorial/src/tutorial28.py

@ -1,4 +1,4 @@
from fastapi import FastAPI, Query, Path
from fastapi import FastAPI, Path, Query
app = FastAPI()

2
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()

9
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

15
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

9
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

8
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

8
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

8
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

11
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

11
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

11
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

11
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

11
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

5
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()

5
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()

5
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()

3
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()

3
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()

6
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()

4
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()
@ -13,7 +12,6 @@ class UserIn(BaseModel):
full_name: str = None
# Don't do this in production!
@app.post("/user/", response_model=UserIn)
async def create_user(*, user: UserIn):

3
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()

5
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)

7
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,6 +18,7 @@ class UserIn(UserBase):
class UserOut(UserBase):
pass
class UserInDB(UserBase):
hashed_password: str
@ -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)

5
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()

5
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()

5
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()

8
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()

7
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()

7
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()

7
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()

14
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:

7
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()

7
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()

7
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()

7
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()

7
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()

9
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

11
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

15
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,6 +26,7 @@ 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
@ -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")

17
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()

15
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():

Loading…
Cancel
Save