I do this in fast api and then pass get_whatever as a dependency to an endpoint
Alternatively you could make use of the lifespan[0] and its state[1][2].
[0]: https://fastapi.tiangolo.com/advanced/events/#lifespan-funct...
[1]: https://asgi.readthedocs.io/en/latest/specs/lifespan.html#li...
[2]: https://www.starlette.io/lifespan/#lifespan-state
Alternatively you could make use of the lifespan[0] and its state[1][2].
[0]: https://fastapi.tiangolo.com/advanced/events/#lifespan-funct...
[1]: https://asgi.readthedocs.io/en/latest/specs/lifespan.html#li...
[2]: https://www.starlette.io/lifespan/#lifespan-state