Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
Is there a way to call an api directly in fastapi whenever backend server starts?

So i have an API which updates weather data in db every hour(using repeat_every decorator). Is there a way to call this API automatically whenever back-end server is up and running instead of manually calling it?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Yes there is. You can define event handlers (functions) that need to be executed before the application starts up and shutting down.

You can use @app.on_event("startup" | "shutdown")

@app.on_event("startup")
async def startup():
    do something...


@app.on_event("shutdown")
async def shutdown():
    do something...

If you are encountring circular import Error, create your api as router than import from your main file.

Example

from fastapi import APIRouter


router = APIRouter()

@router.on_event("startup")
async def startup():
    do something...

And from your main file

from path_to_your_api import router

app.include_router(router)
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda