Python & FastAPI - Annotated Type for Data Validation + Metadata!

Published: 31 January 2024
on channel: BugBytes
7,315
291

In this video, we'll explore the Annotated type in Python, and how it can be used to add metadata to an existing type.

Custom logic can then process that metadata and perform actions based on the values used!

We'll see how Annotated is used in FastAPI with the Query, Path, Header and Cookie parameters to handler functions, and will dive deeper into the internals of the typing module to see how we can extract and process the metadata passed to Annotated.

☕️ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲:
To support the channel and encourage new videos, please consider buying me a coffee here:
https://ko-fi.com/bugbytes

📌 𝗖𝗵𝗮𝗽𝘁𝗲𝗿𝘀:
00:00 Intro
00:59 typing.Annotated - Annotated type in python
04:41 FastAPI annotations with Query and Path object
12:35 Typing module internals
19:07 Creating Decorator for annotation checks

▶️ Full Playlist:

𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮:
📖 Blog: https://bugbytes.io/posts/
👾 Github: https://github.com/bugbytes-io/
🐦 Twitter:   / bugbytesio  

📚 𝗙𝘂𝗿𝘁𝗵𝗲𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗮𝗻𝗱 𝗶𝗻𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝗼𝗻:
Python Typing: https://docs.python.org/3/library/typ...
Annotated: https://docs.python.org/3/library/typ...
FastAPI Query Parameter Annotations: https://fastapi.tiangolo.com/tutorial...
StackOverflow answer: https://stackoverflow.com/questions/6...

#python #fastapi #webdevelopment