Introduction to FastAPI
Matt Eckerle
Software and Data Engineering Leader
Defining a function to get burgers
# This is not asynchronous
def get_sequential_burgers(number: int):
# Do some sequential stuff
return burgers
Calling the function sequentially
burgers = get_burgers(2)
Defining a function to get burgers
async def get_burgers(number: int):
# Do some asynchronous stuff
return burgers
Calling the function asynchronously
burgers = await get_burgers(2)
If we can:
results = await some_library()
Then use async def
:
@app.get('/')
async def read_results():
results = await some_library()
return results
Note Only use
await
inside of functions created withasync def
If our application doesn't have to communicate with anything else and wait for it to respond
Examples
If our application has to communicate with:
If we aren't sure
Introduction to FastAPI