Integrate Spanner with SQLAlchemy ORM (GoogleSQL dialect) Stay organized with collections Save and categorize content based on your preferences.
SQLAlchemy is a Python SQL toolkit and ObjectRelational Mapper.
TheSpanner dialect for SQLAlchemy letsSQLAlchemy users to use Spanner databases. The dialect is built on topof theSpanner API, which is designed inaccordance withPEP-249, and is compatible withSQLAlchemy versions between1.1.13 and1.3.23, and2.0.
Set up the Spanner dialect for SQLAlchemy
To set up the Spanner dialect for SQLAlchemy in your application, install thesqlalchemy-spanner package.
pip3installsqlalchemy-spannerAlternatively, you can install from source.
gitclonehttps://github.com/googleapis/python-spanner-sqlalchemy.gitcdpython-spanner-sqlalchemypythonsetup.pyinstallAs authentication for the Spanner dialect for SQLAlchemy, provide theservice accountJSON credentials file location in theGOOGLE_APPLICATION_CREDENTIALS environment variable. Otherwise, the dialectcan also use the default credentials set in the gcloud CLIapplication.
Use the Spanner dialect for SQLAlchemy
For more information about the available features, limitations of the dialect,recommendations on how to use the dialect, and for code samples, please consultthereference documentation onGitHub.
What's next
- Check out thecode examples on how to use theSpanner dialect for SQLAlchemy.
- View the repository for the Spanner dialect for SQLAlchemy onGitHub.
- File aGitHub issue to report a bug or ask aquestion about the Spanner dialect for SQLAlchemy.
- Learn more aboutSQLAlchemy.
- Learn more aboutPyPI.
- Learn about authorization and authentication credentials inGetting started with authentication.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-19 UTC.