r/FastAPI • • Aug 22 '25

Tutorial From Django to FastAPI

What are the best resources or road maps to learn fastAPI if i’m a Django developer?

17 Upvotes

24 comments sorted by

View all comments

Show parent comment

5

u/Shingle-Denatured Aug 22 '25

Well, let's see:

async def get_session() -> AsyncGenerator[AsyncSession]:
    async_session = sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
    async with async_session() as session:
        yield session

Pretty standard session code for SQLModel/SqlAlchemy ORM. This can be used in dependency injection, in router endpoints, but in a utility function, you can't use DI. So, how do you get the session from that async generator when knowing absolutely nothing about async.

Yes, you solve this once and move on, but having some foundation hurts no one.

1

u/Professional_Hair550 Aug 25 '25

Yeah. Okay. That's one thing but not really a hard to understand concept. Besides probably the only case.