SlideShare a Scribd company logo
5 THINGS ABOUT FASTAPI.
I WISH WE HAD KNOWN BEFOREHAND
ALEXANDER CS HENDORF.
PYCON.IT 2023
THIS TALK IS BASED ON USE CASES.
- DATA MANAGEMENT VIA HUBS / SERVICES.
§ DOMAIN DRIVEN SERVICE CLIENTS.
§ ON PREMS DATA.
§ CLOUD DATA.
§ MIGRATION SZENARIOS.
§ INCLUSIVE ACCESS..
- MICROSERVICES.
WHY FASTAPI.
1. FAST AND HIGH-PERFORMANCE WEB FRAMEWORK
2. EASY TO USE AND LEARN WITH INTUITIVE API DOCUMENTATION
3. SCALABLE AND FLEXIBLE ARCHITECTURE FOR BUILDING APIS
4. AUTOMATIC VALIDATION OF REQUEST AND RESPONSE DATA
5. AUTOMATIC GENERATION OF OPENAPI & JSON SCHEMA
DOCUMENTATION
6. BUILT-IN TESTING FRAMEWORK
7. VERY ACTIVE COMMUNITY
ALEXANDER C. S. HENDORF
MANAGING PARTNER
DATA & AI AT KÖNIGSWEG
PYTHON SOFTWARE FOUNDATION FELLOW, PYTHON SOFTWAREVERBAND CHAIR,
EUROPYTHON BOARD, PYCONDE & PYDATA BERLIN CHAIR
PYDATA FRANKFURT & SÜDWEST
@HENDORF python@hendorf.com
DISCLAIMER.
PARTIALLY OPINIONATED PRESENTATION
! THOUGH
I STILL ❤ FASTAPI
# THANKS TO EVERYONE INVOLVED $%&
A FASTAPI JOURNEY.
- REQUIREMENT
REST API UTILIZING THE OPENAPI STANDARD
- RESEARCH SUGGETS FASTAPI OR CONNEXION
(CONNEXION WAS GREAT BUT UNFORTUNATELY NEGLECTED…)
- PATH TAKEN:
FASTAPI IS THRIVING AND ALIVE: HELLO WORLD IN 5 MINUTES '
- HIGH TRANSFER FROM PREVIOUS REST FRAMEWORKS LIKE FLASK
- ( „FAST API IS ALL ONE NEEDS TO KNOW“
- BUILD STUFF ONE TUTORIAL AT A TIME )
SOME NEXT STEPS
ON THAT JOURNEY.
- ADD MORE ENDPOINTS
- ADD MORE REQUEST MODELS
- ADD MORE RESPONSE MODELS
- ADD COMPLEX MODELS
- ADD VALIDATORS
- BE CONISTENT IN NAMING
- ADD MIDDLEWARE LOGGING
- ADD MIDDLEWARE FOR CONTEXT
- …
SOME NEXT STEPS
ON THAT JOURNEY.
- ADD MORE AND EVEN MORE ENDPOINTS
- ADD MORE AND EVEN MORE REQUEST
MODELS
- ADD MORE AND EVEN MORE RESPONSE
MODELS
- ADD EVEN MORE COMPLEX MODELS
- ADD VALIDATORS
- BE CONISTENT IN NAMING
- ADD AND EVEN MORE MIDDLEWARE
- …
PROJECT GROWTH
- REDUNCANCIES
- REPETITION
SOME CHALLENGES ON THAT JOURNEY.
- ONE NEEDS TO LEARN NOT ONLY FASTAPI BUT
§ PYDANTIC
§ STARLETTE
§ UVICORN
- DESIGN: EVERYTHING IS SOLVED BY ANOTHER LAYER OF
ABSTRACTION: UNCLEAR WHICH LIBRARY IS IN CHARGE *
SOME CHALLENGES ON THAT JOURNEY.
- NEED FOR SUSTAINABLE DESIGN OF ENDPOINTS
- PROBABLY TOO MANY WAYS TO SOLVE THINGS
- CALLS TO OTHER RESOURCES: `async - await`?
- ESTABLISH A ORGANISATION-WIDE STANDARD
- DRY PYDANTIC MODELS NEED A DATA ARCHTITECT
TODAY.
BUILT ON THE SHOULDERS OF GIANTS I..
BUILT ON THE SHOULDERS OF GIANTS II..
GREAT TUTORIALS, BUT IS THIS DOCUMENTATION?.
DON'T REPEAT YOURSELF WITH PYDANTIC.
OPENAPI IN SPHINX.
FASTAPI IS BUILT .
ON THE SHOULDERS OF GIANTS I..
PYDANTIC
STARLETTE
PYDANTIC.
- REQUEST MODELS
- RESPONSE MODELS
- OPENAPI DOCS
PYDANTIC.
- PYDANTIC PARSES THE INPUT DATA
- IF THE DATA CANNOT BE CASTED INTO THE TYPE PYDANTIC RAISES A
USER FRIEDLY EXCEPTION
- ["1", "2", "3"] is a valid List[int] -> [1, 2, 3]
h"ps://docs.pydan.c.dev
PYDANTIC MISUNDERSTOOD.
- VALIDATOR REQUIRES A RETURN VALUE +
- CAN ALSO BE USED TO MANGLE DATA OR DATA CLEANSING ,
- MORE ABOUT VALIDATORS LATER!
PYDANTIC DEFAULTS.
- USE CASE: FRONT END RETIEVES DATA FROM REST BACKEND -
- FE DESIGNER ADDS AN ADDITIONAL PARAMETER currency TO THE
REQUEST
- REQUEST AND RESPONSE MODELS IN PLACE!
- . WE ARE SAVE, AREN'T WE
!KNOW PYDANTIC DEFAULTS.
- FE DESIGNER: THINKS EVERYTHING WORKS, NO ERROR
- BACKEND: DOESN'T NOTICE, DEFAULT IS ` Extra.allow` : UNKNOW
PARAMETERS ARE JUST FILTERED OUT
- `Extra.forbid` ENFORCES CONTRACT
- DESIGN DECISION
FASTAPI IS BUILT .
ON THE SHOULDERS OF GIANTS II..
PYDANTIC
STARLETTE
⭐ STARLETTE.
- "STARLETTE IS A LIGHTWEIGHT ASGI FRAMEWORK/TOOLKIT, WHICH IS
IDEAL FOR BUILDING ASYNC WEB SERVICES IN PYTHON."
§ HTTP WEB FRAMEWORK
§ WEBSOCKET SUPPORT
§ IN-PROCESS BACKGROUND TASKS
§ STARTUP AND SHUTDOWN EVENTS
§ CORS, GZIP, STATIC FILES, STREAMING RESPONSES
§ SESSION AND COOKIE SUPPORT
⭐ SOME STARLETTE.
- CUSTOM PYTHON PACKAGE: INTERFACE TO THE DATA HUB
- DATA CLIENT PROVIDES CONVENIENT, SELF-EXPLANATORY INTERFACES
TO DATA SERVICES ENABLING DEVELOPERS AS WELL AS BUSINESS
USERS.
- client.portfolio.benchmark(id, benchmark=None)
- DATA HUB FASTAPI BE
- ENDPOINT: portfolio/benchmark
Request Model: id, benchmark
- HOW CAN WE GENERATE THE CLIENT AUTOMATICALLY?.
USE CASE: DOMAIN DRIVEN DATA CLIENT.
- CUSTOM PYTHON PACKAGE: INTERFACE TO THE DATA HUB
- DATA CLIENT PROVIDES CONVENIENT, SELF-EXPLANATORY INTERFACES
TO DATA SERVICES ENABLING DEVELOPERS AS WELL AS BUSINESS
USERS.
- client.portfolio.benchmark(id, benchmark=None)
- DATA HUB FASTAPI BE
- ENDPOINT: portfolio/benchmark
Request Model: id, benchmark
- HOW CAN WE GENERATE THE CLIENT AUTOMATICALLY?.
USE CASE: DOMAIN DRIVEN DATA CLIENT.
USE CASE: DOMAIN DRIVEN DATA CLIENT.
- TLDR;
AUTO-GENERATORS BASED ON OPENAPI DID NOT DELIVER CODE
QUALITY EXPECTED
LOSS OF PYTHON OBJECTS OPENAPI IS JSON/YAML
- ✅ SOLUTION: RENDER CODE MEETING OUR STANDARDS WITH JINJA2.
- ISSUE: PATH PARAMETERS AND MODEL PARAMETERS ARE HARD TO
DISTISTINGUISH (AMBIGUTITIES 0)
Q: EG. CAN MIDDLEWARE FIX THIS??
- NEXT STEP: DIVE INTO MIDDLEWARE, WELCOME TO ⭐ STARLETTE !
USE CASE: ENABLING USERS BY SIMPIFING
INTERFACES WITH MIDDLEWARE.
- DON'T TRY THIS AT HOME
- SPIKE: MIDDLEWARE INSPECTS ALL GET REQUESTS ROUTES (INCL. THE
PYDANTIC MODEL) AND MOVES BODY PARAMETERS FROM QUERIES TO
THE REQUEST BODY.
- ✅ MODERATE / ALTER REQUESTS VIA THE MIDDLEWARE
- ✅ HANDLING IS COMPLEX. SOME (FIXABLE BUT UNFORESEEN)
COLLATERAL DAMAGES
- 2 THIS APPROACH FOR A SIMPLER INTERFACE FOR QUERIES WITH
LONGER PARAMETERS DID NOT MEET OUR EXPECTATIONS.
GREAT TUTORIALS.
BUT IS THIS DOCUMENTATION?.
OR WHERE ARE THE DOCSTRINGS?
LET THE DOCSTRINGS OUT.
- FASTAPI 0.95.1 HAS 6022 LINES *
- 259 CLASSES
- 429 FUNCTION OR METHODS
- 11 DOCSTRINGS
- DUE TO DESIGN WITH MANY LAYERS OF ABSTRACTION,
IT'S DIFFICULT TO DEBUG 3
- MORE DOCSTRINGS WOULD BE HELPFUL.
* COUNT EVERY LINE IN FASTAPI: *.PY no dependencies, COUNT """ / 2, COUNT def, COUNT class
LET THE DOCSTRINGS OUT.
- STARLETTE 0.95.1 HAS 6022 LINES *
- 259 CLASSES
- 429 FUNCTION OR METHODS
- 11 DOCSTRINGS
- DUE TO DESIGN WITH MANY LAYERS OF ABSTRACTION,
IT'S DIFFICULT TO DEBUG 3
- MORE DOCSTRINGS WOULD BE HELPFUL.
* COUNT EVERY LINE IN FASTAPI: *.PY no dependencies, COUNT """ / 2, COUNT def, COUNT class
DON'T REPEAT YOURSELF WITH PYDANTIC.
DRY
PYDANTIC.
- ENDPOINT
- RESPONSE MODEL
- OPENAPI DOCS
DRY -DON'T REPEAT YOURSELF- PYDANTIC.
- BETTER ABSTRACTION
- KONSISTENT, REUSEABLE
PYDANTIC INTERITANCE.
- DECOMPOSITIONS INTO SMALL UNITS
§ DRY: DEFINE ONCE INCL. EXAMPLES & VALIDATORS
§ CONSTENCY ACROSS PROJECT OR EVEN ORGANISATION EG. IF
RELEASED AS PACKAGE
- INTERITANCE IS PROBABLY COUNTER INTUITIVE (RIGHT TO LEFT)
PYDANTIC INHERITANCE.
DANGER ZONE!!
USE CASE: DEFINING MODELS FOR AN
ENTIRE ORGANISATION.
- ⭐ INTRODUCE AND ENABLE WITH STANDARDIZARTION 4
- RELEASED AS INTERNAL PACKAGE 5
- 6 CLEAR AND CONCISE DESIGN RULES INCL. NAMING CONVENTIONS
- CENTRALISATION: UPDATES NEED TO BE COORDINATED 7
- LESSONS LEARNED:
§ FOCUS ON DEFINED, CROSS ORGANISATION ATTRIBUTES
§ HAVE SERVICES DESIGN CUSTOM MODELS
5 THINGS ABOUT FASTAPI WE ❤.
ACCESSIBLILITY VIA INTROSPECTION IS GREAT.
DYNAMIC CREATION OF ROUTERS.
CUSTOM VALIDATON ERROR HANDLING .
MIDDLEWARE EASY TO ADD.
5 MORE THINGS !!.
OPENAPI IN SPHINX.
- sphinxcontrib-openapi EXTENSION 8
- DOCS: h?ps://sphinxcontrib-openapi.readthedocs.io/
- ADD TO SPHINX EXTENSIONS (JUST AS OTHERS)
- EXPORT OPENAPI DEF IN YAML
- ADD TO YOUR INDEX %
TALK
What does Starlette really
do for FastAPI?
Saturday, May 27
16:00 - 16:30
LANGUAGE
English
AUDIENCE LEVEL
Intermediate
ELEVATOR PITCH
FastAPI has been growing a lot lately, but people aren’t really aware of the
packages that were the basis for its foundation.
On this talk, we are going to explore Starlette, the web framework on which
FastAPI is built on top of.
ABSTRACT
Starlette is the package that contains the core logic of FastAPI. It’s a timid, and less known
project in comparison to the latter.
We’ll understand what Starlette really is, and what it does for FastAPI. We are going to
explore both frameworks in a comparative way, to understand the things that are
responsibility from one package and the other.
After this talk, you are going to understand more about the internals of one of the most
popular web frameworks in Python.
TAGS
AsyncIO, APIs, Microservices, FastAPI, Starlette
Marcelo Trylesinski
16:00 - 16:30
LANGUAGE
English
AUDIENCE LEVEL
Intermediate
ELEVATOR PITCH
FastAPI has been growing a lot lately, but people aren’t really aware of the
packages that were the basis for its foundation.
On this talk, we are going to explore Starlette, the web framework on which
FastAPI is built on top of.
ABSTRACT
Starlette is the package that contains the core logic of FastAPI. It’s a timid, and less known
project in comparison to the latter.
We’ll understand what Starlette really is, and what it does for FastAPI. We are going to
explore both frameworks in a comparative way, to understand the things that are
responsibility from one package and the other.
After this talk, you are going to understand more about the internals of one of the most
popular web frameworks in Python.
TAGS
AsyncIO, APIs, Microservices, FastAPI, Starlette
Marcelo Trylesinski
Software Engineer
Uvicorn & Starlette maintainer
FastAPI Expert ⚡
THANK YOU!!
Q&A!
@HENDORF / LINKEDIN
THANKS TO MY COLLEAGUES AND PEERS FOR ALL INPUT AND DISCUSSIONS ON
RESULTS PRESENTED HERE: ALEX S. DIMITRI S. FLORIAN P. STEPHAN G.!
THANKS TO LAMBDALABS FOR SHARING STABLE DIFFUSION IMAGE
VARIATIONS $ THANKS TO MAX ERNST FOR PAINTING $

More Related Content

Similar to 5 Things about fastAPI I wish we had known beforehand

Use Case Patterns for LLM Applications (1).pdf
Use Case Patterns for LLM Applications (1).pdfUse Case Patterns for LLM Applications (1).pdf
Use Case Patterns for LLM Applications (1).pdf
M Waleed Kadous
 
Agile data lake? An oxymoron?
Agile data lake? An oxymoron?Agile data lake? An oxymoron?
Agile data lake? An oxymoron?
samthemonad
 
Demystify Information Security & Threats for Data-Driven Platforms With Cheta...
Demystify Information Security & Threats for Data-Driven Platforms With Cheta...Demystify Information Security & Threats for Data-Driven Platforms With Cheta...
Demystify Information Security & Threats for Data-Driven Platforms With Cheta...
Chetan Khatri
 
Data-Driven Transformation: Leveraging Big Data at Showtime with Apache Spark
Data-Driven Transformation: Leveraging Big Data at Showtime with Apache SparkData-Driven Transformation: Leveraging Big Data at Showtime with Apache Spark
Data-Driven Transformation: Leveraging Big Data at Showtime with Apache Spark
Databricks
 
II-SDV 2014 Search and Data Mining Open Source Platforms (Patrick Beaucamp - ...
II-SDV 2014 Search and Data Mining Open Source Platforms (Patrick Beaucamp - ...II-SDV 2014 Search and Data Mining Open Source Platforms (Patrick Beaucamp - ...
II-SDV 2014 Search and Data Mining Open Source Platforms (Patrick Beaucamp - ...Dr. Haxel Consult
 
Practical Chaos Engineering
Practical Chaos EngineeringPractical Chaos Engineering
Practical Chaos Engineering
SIGHUP
 
Future of Data Platform in Cloud Native world
Future of Data Platform in Cloud Native worldFuture of Data Platform in Cloud Native world
Future of Data Platform in Cloud Native world
Srivatsan Srinivasan
 
How to Share and Reuse Learning Resources: the ARIADNE Experience
How to Share and Reuse Learning Resources: the ARIADNE ExperienceHow to Share and Reuse Learning Resources: the ARIADNE Experience
How to Share and Reuse Learning Resources: the ARIADNE ExperienceJoris Klerkx
 
Surviving Berlin Winter with JavaScript
Surviving Berlin Winter with JavaScriptSurviving Berlin Winter with JavaScript
Surviving Berlin Winter with JavaScript
Julian Kern
 
Build agile and elastic data pipeline
Build agile and elastic data pipelineBuild agile and elastic data pipeline
Build agile and elastic data pipeline
Deba Chatterjee
 
JustEnoughDevOpsForDataScientists
JustEnoughDevOpsForDataScientistsJustEnoughDevOpsForDataScientists
JustEnoughDevOpsForDataScientists
Anya Bida
 
Advancing Open Software Defined Storage
Advancing Open Software Defined Storage Advancing Open Software Defined Storage
Advancing Open Software Defined Storage
Red_Hat_Storage
 
Serverless in production, an experience report (FullStack 2018)
Serverless in production, an experience report (FullStack 2018)Serverless in production, an experience report (FullStack 2018)
Serverless in production, an experience report (FullStack 2018)
Yan Cui
 
Cowboy dating with big data TechDays at Lohika-2020
Cowboy dating with big data TechDays at Lohika-2020Cowboy dating with big data TechDays at Lohika-2020
Cowboy dating with big data TechDays at Lohika-2020
b0ris_1
 
Customer Applications Of Hadoop On Red Hat Storage Server
Customer Applications Of Hadoop On Red Hat Storage ServerCustomer Applications Of Hadoop On Red Hat Storage Server
Customer Applications Of Hadoop On Red Hat Storage Server
Red_Hat_Storage
 
Building on AWS Cloud One Codebase Aberdeen 25-apr-19
Building on AWS Cloud One Codebase Aberdeen 25-apr-19Building on AWS Cloud One Codebase Aberdeen 25-apr-19
Building on AWS Cloud One Codebase Aberdeen 25-apr-19
Cloudsoft
 
DevOps for DataScience
DevOps for DataScienceDevOps for DataScience
DevOps for DataScience
Stepan Pushkarev
 
Serverless in production, an experience report (IWOMM)
Serverless in production, an experience report (IWOMM)Serverless in production, an experience report (IWOMM)
Serverless in production, an experience report (IWOMM)
Yan Cui
 
Oasis: Standards & the Cloud June2011
Oasis: Standards & the Cloud June2011Oasis: Standards & the Cloud June2011
Oasis: Standards & the Cloud June2011
Jamie Clark
 

Similar to 5 Things about fastAPI I wish we had known beforehand (20)

Use Case Patterns for LLM Applications (1).pdf
Use Case Patterns for LLM Applications (1).pdfUse Case Patterns for LLM Applications (1).pdf
Use Case Patterns for LLM Applications (1).pdf
 
Agile data lake? An oxymoron?
Agile data lake? An oxymoron?Agile data lake? An oxymoron?
Agile data lake? An oxymoron?
 
Demystify Information Security & Threats for Data-Driven Platforms With Cheta...
Demystify Information Security & Threats for Data-Driven Platforms With Cheta...Demystify Information Security & Threats for Data-Driven Platforms With Cheta...
Demystify Information Security & Threats for Data-Driven Platforms With Cheta...
 
Data-Driven Transformation: Leveraging Big Data at Showtime with Apache Spark
Data-Driven Transformation: Leveraging Big Data at Showtime with Apache SparkData-Driven Transformation: Leveraging Big Data at Showtime with Apache Spark
Data-Driven Transformation: Leveraging Big Data at Showtime with Apache Spark
 
II-SDV 2014 Search and Data Mining Open Source Platforms (Patrick Beaucamp - ...
II-SDV 2014 Search and Data Mining Open Source Platforms (Patrick Beaucamp - ...II-SDV 2014 Search and Data Mining Open Source Platforms (Patrick Beaucamp - ...
II-SDV 2014 Search and Data Mining Open Source Platforms (Patrick Beaucamp - ...
 
Practical Chaos Engineering
Practical Chaos EngineeringPractical Chaos Engineering
Practical Chaos Engineering
 
Future of Data Platform in Cloud Native world
Future of Data Platform in Cloud Native worldFuture of Data Platform in Cloud Native world
Future of Data Platform in Cloud Native world
 
How to Share and Reuse Learning Resources: the ARIADNE Experience
How to Share and Reuse Learning Resources: the ARIADNE ExperienceHow to Share and Reuse Learning Resources: the ARIADNE Experience
How to Share and Reuse Learning Resources: the ARIADNE Experience
 
Surviving Berlin Winter with JavaScript
Surviving Berlin Winter with JavaScriptSurviving Berlin Winter with JavaScript
Surviving Berlin Winter with JavaScript
 
Build agile and elastic data pipeline
Build agile and elastic data pipelineBuild agile and elastic data pipeline
Build agile and elastic data pipeline
 
JustEnoughDevOpsForDataScientists
JustEnoughDevOpsForDataScientistsJustEnoughDevOpsForDataScientists
JustEnoughDevOpsForDataScientists
 
Why Startups Are Still On AWS
Why Startups Are Still On AWSWhy Startups Are Still On AWS
Why Startups Are Still On AWS
 
Advancing Open Software Defined Storage
Advancing Open Software Defined Storage Advancing Open Software Defined Storage
Advancing Open Software Defined Storage
 
Serverless in production, an experience report (FullStack 2018)
Serverless in production, an experience report (FullStack 2018)Serverless in production, an experience report (FullStack 2018)
Serverless in production, an experience report (FullStack 2018)
 
Cowboy dating with big data TechDays at Lohika-2020
Cowboy dating with big data TechDays at Lohika-2020Cowboy dating with big data TechDays at Lohika-2020
Cowboy dating with big data TechDays at Lohika-2020
 
Customer Applications Of Hadoop On Red Hat Storage Server
Customer Applications Of Hadoop On Red Hat Storage ServerCustomer Applications Of Hadoop On Red Hat Storage Server
Customer Applications Of Hadoop On Red Hat Storage Server
 
Building on AWS Cloud One Codebase Aberdeen 25-apr-19
Building on AWS Cloud One Codebase Aberdeen 25-apr-19Building on AWS Cloud One Codebase Aberdeen 25-apr-19
Building on AWS Cloud One Codebase Aberdeen 25-apr-19
 
DevOps for DataScience
DevOps for DataScienceDevOps for DataScience
DevOps for DataScience
 
Serverless in production, an experience report (IWOMM)
Serverless in production, an experience report (IWOMM)Serverless in production, an experience report (IWOMM)
Serverless in production, an experience report (IWOMM)
 
Oasis: Standards & the Cloud June2011
Oasis: Standards & the Cloud June2011Oasis: Standards & the Cloud June2011
Oasis: Standards & the Cloud June2011
 

Recently uploaded

一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
ewymefz
 
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
axoqas
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
ukgaet
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
TravisMalana
 
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
v3tuleee
 
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
nscud
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
Subhajit Sahu
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
slg6lamcq
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 
一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
enxupq
 
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
pchutichetpong
 
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape ReportSOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar
 
社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .
NABLAS株式会社
 
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
slg6lamcq
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
vcaxypu
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Subhajit Sahu
 
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
u86oixdj
 
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
John Andrews
 
FP Growth Algorithm and its Applications
FP Growth Algorithm and its ApplicationsFP Growth Algorithm and its Applications
FP Growth Algorithm and its Applications
MaleehaSheikh2
 

Recently uploaded (20)

一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
 
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
 
Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)Malana- Gimlet Market Analysis (Portfolio 2)
Malana- Gimlet Market Analysis (Portfolio 2)
 
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理一比一原版(UofS毕业证书)萨省大学毕业证如何办理
一比一原版(UofS毕业证书)萨省大学毕业证如何办理
 
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
一比一原版(CBU毕业证)卡普顿大学毕业证成绩单
 
Adjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTESAdjusting primitives for graph : SHORT REPORT / NOTES
Adjusting primitives for graph : SHORT REPORT / NOTES
 
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
一比一原版(UniSA毕业证书)南澳大学毕业证如何办理
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 
一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
 
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
Data Centers - Striving Within A Narrow Range - Research Report - MCG - May 2...
 
SOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape ReportSOCRadar Germany 2024 Threat Landscape Report
SOCRadar Germany 2024 Threat Landscape Report
 
社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .社内勉強会資料_LLM Agents                              .
社内勉強会資料_LLM Agents                              .
 
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
一比一原版(RUG毕业证)格罗宁根大学毕业证成绩单
 
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
Algorithmic optimizations for Dynamic Levelwise PageRank (from STICD) : SHORT...
 
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
原版制作(Deakin毕业证书)迪肯大学毕业证学位证一模一样
 
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
Chatty Kathy - UNC Bootcamp Final Project Presentation - Final Version - 5.23...
 
FP Growth Algorithm and its Applications
FP Growth Algorithm and its ApplicationsFP Growth Algorithm and its Applications
FP Growth Algorithm and its Applications
 

5 Things about fastAPI I wish we had known beforehand

  • 1. 5 THINGS ABOUT FASTAPI. I WISH WE HAD KNOWN BEFOREHAND ALEXANDER CS HENDORF. PYCON.IT 2023
  • 2. THIS TALK IS BASED ON USE CASES. - DATA MANAGEMENT VIA HUBS / SERVICES. § DOMAIN DRIVEN SERVICE CLIENTS. § ON PREMS DATA. § CLOUD DATA. § MIGRATION SZENARIOS. § INCLUSIVE ACCESS.. - MICROSERVICES.
  • 3. WHY FASTAPI. 1. FAST AND HIGH-PERFORMANCE WEB FRAMEWORK 2. EASY TO USE AND LEARN WITH INTUITIVE API DOCUMENTATION 3. SCALABLE AND FLEXIBLE ARCHITECTURE FOR BUILDING APIS 4. AUTOMATIC VALIDATION OF REQUEST AND RESPONSE DATA 5. AUTOMATIC GENERATION OF OPENAPI & JSON SCHEMA DOCUMENTATION 6. BUILT-IN TESTING FRAMEWORK 7. VERY ACTIVE COMMUNITY
  • 4. ALEXANDER C. S. HENDORF MANAGING PARTNER DATA & AI AT KÖNIGSWEG PYTHON SOFTWARE FOUNDATION FELLOW, PYTHON SOFTWAREVERBAND CHAIR, EUROPYTHON BOARD, PYCONDE & PYDATA BERLIN CHAIR PYDATA FRANKFURT & SÜDWEST @HENDORF python@hendorf.com
  • 5. DISCLAIMER. PARTIALLY OPINIONATED PRESENTATION ! THOUGH I STILL ❤ FASTAPI # THANKS TO EVERYONE INVOLVED $%&
  • 6. A FASTAPI JOURNEY. - REQUIREMENT REST API UTILIZING THE OPENAPI STANDARD - RESEARCH SUGGETS FASTAPI OR CONNEXION (CONNEXION WAS GREAT BUT UNFORTUNATELY NEGLECTED…) - PATH TAKEN: FASTAPI IS THRIVING AND ALIVE: HELLO WORLD IN 5 MINUTES ' - HIGH TRANSFER FROM PREVIOUS REST FRAMEWORKS LIKE FLASK - ( „FAST API IS ALL ONE NEEDS TO KNOW“ - BUILD STUFF ONE TUTORIAL AT A TIME )
  • 7. SOME NEXT STEPS ON THAT JOURNEY. - ADD MORE ENDPOINTS - ADD MORE REQUEST MODELS - ADD MORE RESPONSE MODELS - ADD COMPLEX MODELS - ADD VALIDATORS - BE CONISTENT IN NAMING - ADD MIDDLEWARE LOGGING - ADD MIDDLEWARE FOR CONTEXT - …
  • 8. SOME NEXT STEPS ON THAT JOURNEY. - ADD MORE AND EVEN MORE ENDPOINTS - ADD MORE AND EVEN MORE REQUEST MODELS - ADD MORE AND EVEN MORE RESPONSE MODELS - ADD EVEN MORE COMPLEX MODELS - ADD VALIDATORS - BE CONISTENT IN NAMING - ADD AND EVEN MORE MIDDLEWARE - …
  • 10. SOME CHALLENGES ON THAT JOURNEY. - ONE NEEDS TO LEARN NOT ONLY FASTAPI BUT § PYDANTIC § STARLETTE § UVICORN - DESIGN: EVERYTHING IS SOLVED BY ANOTHER LAYER OF ABSTRACTION: UNCLEAR WHICH LIBRARY IS IN CHARGE *
  • 11. SOME CHALLENGES ON THAT JOURNEY. - NEED FOR SUSTAINABLE DESIGN OF ENDPOINTS - PROBABLY TOO MANY WAYS TO SOLVE THINGS - CALLS TO OTHER RESOURCES: `async - await`? - ESTABLISH A ORGANISATION-WIDE STANDARD - DRY PYDANTIC MODELS NEED A DATA ARCHTITECT
  • 12. TODAY. BUILT ON THE SHOULDERS OF GIANTS I.. BUILT ON THE SHOULDERS OF GIANTS II.. GREAT TUTORIALS, BUT IS THIS DOCUMENTATION?. DON'T REPEAT YOURSELF WITH PYDANTIC. OPENAPI IN SPHINX.
  • 13. FASTAPI IS BUILT . ON THE SHOULDERS OF GIANTS I.. PYDANTIC STARLETTE
  • 14. PYDANTIC. - REQUEST MODELS - RESPONSE MODELS - OPENAPI DOCS
  • 15. PYDANTIC. - PYDANTIC PARSES THE INPUT DATA - IF THE DATA CANNOT BE CASTED INTO THE TYPE PYDANTIC RAISES A USER FRIEDLY EXCEPTION - ["1", "2", "3"] is a valid List[int] -> [1, 2, 3] h"ps://docs.pydan.c.dev
  • 16. PYDANTIC MISUNDERSTOOD. - VALIDATOR REQUIRES A RETURN VALUE + - CAN ALSO BE USED TO MANGLE DATA OR DATA CLEANSING , - MORE ABOUT VALIDATORS LATER!
  • 17. PYDANTIC DEFAULTS. - USE CASE: FRONT END RETIEVES DATA FROM REST BACKEND - - FE DESIGNER ADDS AN ADDITIONAL PARAMETER currency TO THE REQUEST - REQUEST AND RESPONSE MODELS IN PLACE! - . WE ARE SAVE, AREN'T WE
  • 18. !KNOW PYDANTIC DEFAULTS. - FE DESIGNER: THINKS EVERYTHING WORKS, NO ERROR - BACKEND: DOESN'T NOTICE, DEFAULT IS ` Extra.allow` : UNKNOW PARAMETERS ARE JUST FILTERED OUT - `Extra.forbid` ENFORCES CONTRACT - DESIGN DECISION
  • 19. FASTAPI IS BUILT . ON THE SHOULDERS OF GIANTS II.. PYDANTIC STARLETTE
  • 20. ⭐ STARLETTE. - "STARLETTE IS A LIGHTWEIGHT ASGI FRAMEWORK/TOOLKIT, WHICH IS IDEAL FOR BUILDING ASYNC WEB SERVICES IN PYTHON." § HTTP WEB FRAMEWORK § WEBSOCKET SUPPORT § IN-PROCESS BACKGROUND TASKS § STARTUP AND SHUTDOWN EVENTS § CORS, GZIP, STATIC FILES, STREAMING RESPONSES § SESSION AND COOKIE SUPPORT
  • 22. - CUSTOM PYTHON PACKAGE: INTERFACE TO THE DATA HUB - DATA CLIENT PROVIDES CONVENIENT, SELF-EXPLANATORY INTERFACES TO DATA SERVICES ENABLING DEVELOPERS AS WELL AS BUSINESS USERS. - client.portfolio.benchmark(id, benchmark=None) - DATA HUB FASTAPI BE - ENDPOINT: portfolio/benchmark Request Model: id, benchmark - HOW CAN WE GENERATE THE CLIENT AUTOMATICALLY?. USE CASE: DOMAIN DRIVEN DATA CLIENT.
  • 23. - CUSTOM PYTHON PACKAGE: INTERFACE TO THE DATA HUB - DATA CLIENT PROVIDES CONVENIENT, SELF-EXPLANATORY INTERFACES TO DATA SERVICES ENABLING DEVELOPERS AS WELL AS BUSINESS USERS. - client.portfolio.benchmark(id, benchmark=None) - DATA HUB FASTAPI BE - ENDPOINT: portfolio/benchmark Request Model: id, benchmark - HOW CAN WE GENERATE THE CLIENT AUTOMATICALLY?. USE CASE: DOMAIN DRIVEN DATA CLIENT.
  • 24.
  • 25. USE CASE: DOMAIN DRIVEN DATA CLIENT. - TLDR; AUTO-GENERATORS BASED ON OPENAPI DID NOT DELIVER CODE QUALITY EXPECTED LOSS OF PYTHON OBJECTS OPENAPI IS JSON/YAML - ✅ SOLUTION: RENDER CODE MEETING OUR STANDARDS WITH JINJA2. - ISSUE: PATH PARAMETERS AND MODEL PARAMETERS ARE HARD TO DISTISTINGUISH (AMBIGUTITIES 0) Q: EG. CAN MIDDLEWARE FIX THIS?? - NEXT STEP: DIVE INTO MIDDLEWARE, WELCOME TO ⭐ STARLETTE !
  • 26. USE CASE: ENABLING USERS BY SIMPIFING INTERFACES WITH MIDDLEWARE. - DON'T TRY THIS AT HOME - SPIKE: MIDDLEWARE INSPECTS ALL GET REQUESTS ROUTES (INCL. THE PYDANTIC MODEL) AND MOVES BODY PARAMETERS FROM QUERIES TO THE REQUEST BODY. - ✅ MODERATE / ALTER REQUESTS VIA THE MIDDLEWARE - ✅ HANDLING IS COMPLEX. SOME (FIXABLE BUT UNFORESEEN) COLLATERAL DAMAGES - 2 THIS APPROACH FOR A SIMPLER INTERFACE FOR QUERIES WITH LONGER PARAMETERS DID NOT MEET OUR EXPECTATIONS.
  • 27. GREAT TUTORIALS. BUT IS THIS DOCUMENTATION?. OR WHERE ARE THE DOCSTRINGS?
  • 28. LET THE DOCSTRINGS OUT. - FASTAPI 0.95.1 HAS 6022 LINES * - 259 CLASSES - 429 FUNCTION OR METHODS - 11 DOCSTRINGS - DUE TO DESIGN WITH MANY LAYERS OF ABSTRACTION, IT'S DIFFICULT TO DEBUG 3 - MORE DOCSTRINGS WOULD BE HELPFUL. * COUNT EVERY LINE IN FASTAPI: *.PY no dependencies, COUNT """ / 2, COUNT def, COUNT class
  • 29. LET THE DOCSTRINGS OUT. - STARLETTE 0.95.1 HAS 6022 LINES * - 259 CLASSES - 429 FUNCTION OR METHODS - 11 DOCSTRINGS - DUE TO DESIGN WITH MANY LAYERS OF ABSTRACTION, IT'S DIFFICULT TO DEBUG 3 - MORE DOCSTRINGS WOULD BE HELPFUL. * COUNT EVERY LINE IN FASTAPI: *.PY no dependencies, COUNT """ / 2, COUNT def, COUNT class
  • 30. DON'T REPEAT YOURSELF WITH PYDANTIC. DRY
  • 31. PYDANTIC. - ENDPOINT - RESPONSE MODEL - OPENAPI DOCS
  • 32. DRY -DON'T REPEAT YOURSELF- PYDANTIC. - BETTER ABSTRACTION - KONSISTENT, REUSEABLE
  • 33. PYDANTIC INTERITANCE. - DECOMPOSITIONS INTO SMALL UNITS § DRY: DEFINE ONCE INCL. EXAMPLES & VALIDATORS § CONSTENCY ACROSS PROJECT OR EVEN ORGANISATION EG. IF RELEASED AS PACKAGE - INTERITANCE IS PROBABLY COUNTER INTUITIVE (RIGHT TO LEFT)
  • 35. USE CASE: DEFINING MODELS FOR AN ENTIRE ORGANISATION. - ⭐ INTRODUCE AND ENABLE WITH STANDARDIZARTION 4 - RELEASED AS INTERNAL PACKAGE 5 - 6 CLEAR AND CONCISE DESIGN RULES INCL. NAMING CONVENTIONS - CENTRALISATION: UPDATES NEED TO BE COORDINATED 7 - LESSONS LEARNED: § FOCUS ON DEFINED, CROSS ORGANISATION ATTRIBUTES § HAVE SERVICES DESIGN CUSTOM MODELS
  • 36. 5 THINGS ABOUT FASTAPI WE ❤. ACCESSIBLILITY VIA INTROSPECTION IS GREAT. DYNAMIC CREATION OF ROUTERS. CUSTOM VALIDATON ERROR HANDLING . MIDDLEWARE EASY TO ADD. 5 MORE THINGS !!.
  • 37. OPENAPI IN SPHINX. - sphinxcontrib-openapi EXTENSION 8 - DOCS: h?ps://sphinxcontrib-openapi.readthedocs.io/ - ADD TO SPHINX EXTENSIONS (JUST AS OTHERS) - EXPORT OPENAPI DEF IN YAML - ADD TO YOUR INDEX %
  • 38.
  • 39. TALK What does Starlette really do for FastAPI? Saturday, May 27 16:00 - 16:30 LANGUAGE English AUDIENCE LEVEL Intermediate ELEVATOR PITCH FastAPI has been growing a lot lately, but people aren’t really aware of the packages that were the basis for its foundation. On this talk, we are going to explore Starlette, the web framework on which FastAPI is built on top of. ABSTRACT Starlette is the package that contains the core logic of FastAPI. It’s a timid, and less known project in comparison to the latter. We’ll understand what Starlette really is, and what it does for FastAPI. We are going to explore both frameworks in a comparative way, to understand the things that are responsibility from one package and the other. After this talk, you are going to understand more about the internals of one of the most popular web frameworks in Python. TAGS AsyncIO, APIs, Microservices, FastAPI, Starlette Marcelo Trylesinski 16:00 - 16:30 LANGUAGE English AUDIENCE LEVEL Intermediate ELEVATOR PITCH FastAPI has been growing a lot lately, but people aren’t really aware of the packages that were the basis for its foundation. On this talk, we are going to explore Starlette, the web framework on which FastAPI is built on top of. ABSTRACT Starlette is the package that contains the core logic of FastAPI. It’s a timid, and less known project in comparison to the latter. We’ll understand what Starlette really is, and what it does for FastAPI. We are going to explore both frameworks in a comparative way, to understand the things that are responsibility from one package and the other. After this talk, you are going to understand more about the internals of one of the most popular web frameworks in Python. TAGS AsyncIO, APIs, Microservices, FastAPI, Starlette Marcelo Trylesinski Software Engineer Uvicorn & Starlette maintainer FastAPI Expert ⚡
  • 40. THANK YOU!! Q&A! @HENDORF / LINKEDIN THANKS TO MY COLLEAGUES AND PEERS FOR ALL INPUT AND DISCUSSIONS ON RESULTS PRESENTED HERE: ALEX S. DIMITRI S. FLORIAN P. STEPHAN G.! THANKS TO LAMBDALABS FOR SHARING STABLE DIFFUSION IMAGE VARIATIONS $ THANKS TO MAX ERNST FOR PAINTING $