Introdução ao FastAPI
Matt Eckerle
Software and Data Engineering Leader


Definindo uma função para obter hambúrgueres
# This is not asynchronous
def get_sequential_burgers(number: int):
# Do some sequential stuff
return burgers
Chamando a função de forma sequencial
burgers = get_burgers(2)
Definindo uma função para obter hambúrgueres
async def get_burgers(number: int):
# Do some asynchronous stuff
return burgers
Chamando a função de forma assíncrona
burgers = await get_burgers(2)
Se for possível:
results = await some_library()
Então use async def:
@app.get('/')
async def read_results():
results = await some_library()
return results
Observação Use
awaitapenas dentro de funções criadas comasync def
Se nosso aplicativo precisa esperar respostas de outros sistemas
Exemplos
Tarefas pesadas de CPU
Exemplos
Se não tivermos certeza
Introdução ao FastAPI