SQLAlchemy and Alembic 2 · Querying

Get exactly one row

scalar_one() raises if there is not exactly one match; first() returns None for no match.

user = session.scalars(select(User).where(User.email == "[email protected]")).one()

Official SQLAlchemy and Alembic 2 documentation

More querying commands

All querying commands · SQLAlchemy and Alembic 2 cheatsheet

Was this page helpful?