from typing import Set
from fastapi import FastAPI
-from pydantic import BaseModel
-from pydantic.types import UrlStr
+from pydantic import BaseModel, UrlStr
app = FastAPI()
from typing import List, Set
from fastapi import FastAPI
-from pydantic import BaseModel
-from pydantic.types import UrlStr
+from pydantic import BaseModel, UrlStr
app = FastAPI()
price: float
tax: float = None
tags: Set[str] = []
- image: List[Image] = None
+ images: List[Image] = None
@app.put("/items/{item_id}")
from typing import List, Set
from fastapi import FastAPI
-from pydantic import BaseModel
-from pydantic.types import UrlStr
+from pydantic import BaseModel, UrlStr
app = FastAPI()
price: float
tax: float = None
tags: Set[str] = []
- image: List[Image] = None
+ images: List[Image] = None
class Offer(BaseModel):
from typing import List
from fastapi import FastAPI
-from pydantic import BaseModel
-from pydantic.types import UrlStr
+from pydantic import BaseModel, UrlStr
app = FastAPI()
For example, as in the `Image` model we have a `url` field, we can declare it to be instead of a `str`, a Pydantic's `UrlStr`:
-```Python hl_lines="5 11"
+```Python hl_lines="4 10"
{!./src/body_nested_models/tutorial005.py!}
```
You can also use Pydantic models as subtypes of `list`, `set`, etc:
-```Python hl_lines="21"
+```Python hl_lines="20"
{!./src/body_nested_models/tutorial006.py!}
```
You can define arbitrarily deeply nested models:
-```Python hl_lines="10 15 21 24 28"
+```Python hl_lines="9 14 20 23 27"
{!./src/body_nested_models/tutorial007.py!}
```
as in:
-```Python hl_lines="16"
+```Python hl_lines="15"
{!./src/body_nested_models/tutorial008.py!}
```
## Install `PyJWT`
-We need to install `PyJWT` to generate and verity the JWT tokens in Python:
+We need to install `PyJWT` to generate and verify the JWT tokens in Python:
```bash
pip install pyjwt
**FastAPI** doesn't make any compromise with any database, data model or tool.
-It gives you all the flexibility to chose the ones that fit your project the best.
+It gives you all the flexibility to choose the ones that fit your project the best.
And you can use directly many well maintained and widely used packages like `passlib` and `pyjwt`, because **FastAPI** doesn't require any complex mechanisms to integrate external packages.