Accessing the `app` in `Depends`
See original GitHub issueI would like to access the FastAPI
app in a Depends
function, is there a way to do that?
The rationale here is that I would like to avoid global variables and use the state
in app
.
Example usecase:
def get_session(app: fastapi.FastAPI) -> Session:
[...]
access the app.state here
[...]
@router.post("/init")
def create(session: Session = Depends(get_session)):
[...]
use the SQLAlchemy session
[...]
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
What is Application Dependency? | Palo Alto Networks
The "Implicitly Use Applications" is a subset of "Depends on," and the dependent applications are implicitly allowed. The application still does ...
Read more >Manual dependency injection - Android Developers
Basics of manual dependency injection It walks through an iterated approach of how you might start using dependency injection in your app. The ......
Read more >Dependencies - First Steps - FastAPI - tiangolo
Declare the dependency, in the "dependant"¶. The same way you use Body , Query , etc. with your path operation function parameters, use...
Read more >Dependency Walker (depends.exe) Home Page
Dependency Walker is a free utility that scans any 32-bit or 64-bit Windows module (exe, dll, ocx, sys, etc.) and builds a hierarchical...
Read more >FastAPI Depends use-case application - python - Stack Overflow
@app.on_event("startup") async def start(): parser = ArgumentParser(. ... and overwrite a property declared inside the class to be accessed ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This works for me:
Thanks for the help here @chbndrhnns ! 👏 🙇
Thanks for reporting back and closing the issue @nicolaerosia 👍