Python: post #2263838 — TG.ME

razorblade23SessionDep is Session Dependancy for short. Its annotated type which resolves get_session() function on each request that needs the session (as stated in route definition) Depends is something FastAPI uses to resolve those dependacies - and yes, di-flask…
i really read this a lot last some days see what i understand is,

def get_session():
with Session(engine) as session:
yield session

@app.post("/heroes/", response_model=HeroPublic)
def create_hero(*, session: Session = Depends(get_session), hero: HeroCreate):


so this session=Depends() is only valid for fastapi web dev things, so suppose i am using a normal cli app or anything that will do some database writting on some several time on my private os, then in this case i have a another thing which is not a web app ,so in thay case i cannot use the SessionDep logic like this, it is for only fastapi web and other case like tg bot api code, cli code i need to write full sqlmodel databsse operation function with session(engine) block always?
August 25, 2026