[Python] FastAPI - How to get app instance inside a router?

Discussão em 'Python' iniciado por Stack, Maio 25, 2025.

  1. Stack

    Stack Membro Participativo

    I want to get the app instance in my router file, what should I do ?

    My main.py is as follows:

    # ...
    app = FastAPI()
    app.machine_learning_model = joblib.load(some_path)
    app.include_router(some_router)
    # ...


    Now I want to use app.machine_learning_model in some_router's file , what should I do ?

    Continue reading...

Compartilhe esta Página