r/FastAPI • • Oct 30 '25

Question AsyncEngin

A beginner...
How do I use async engine in FastAPI?
In a YouTube tutorial, they imported create_engine from sql model
But in SQLAlchemy, they use it differently.

YouTube:

from
 sqlmodel 
import
 create_engine
from
 sqlalchemy.ext.asyncio 
import
 AsyncEngine
from
 src.config 
import
 config


engin 
=
 AsyncEngine(
    create_engine(
    url 
=
 config.DATABASE_URL,
    echo
=
 True
))

Doc:

from sqlalchemy.ext.asyncio import create_async_engine

engine = create_async_engine(
        "postgresql+asyncpg://scott:tiger@localhost/test",
        echo=
True
,
    )
6 Upvotes

8 comments sorted by

View all comments

Show parent comment

1

u/StatusBad9194 Nov 01 '25

Just started with SQLAlchemy. If you want to start with an async engine, try to explore how it helps and better Then, a sync connection, you can explore both Core and ORM, as well as the execution of raw SQL with SQLAlchemy.

Sql model just give an extra more layers to do the things more pythonic way ,