Integrate Spanner with SQLAlchemy ORM (GoogleSQL dialect)

SQLAlchemy is a Python SQL toolkit and Object Relational Mapper.

The Spanner dialect for SQLAlchemy lets SQLAlchemy users to use Spanner databases. The dialect is built on top of the Spanner API , which is designed in accordance with PEP-249 , and is compatible with SQLAlchemy versions between 1.1.13 and 1.3.23 , and 2.0 .

Set up the Spanner dialect for SQLAlchemy

To set up the Spanner dialect for SQLAlchemy in your application, install the sqlalchemy-spanner package .

  pip3 
  
 install 
  
 sqlalchemy 
 - 
 spanner 
 

Alternatively, you can install from source.

  git 
  
 clone 
  
 https 
 : 
 // 
 github 
 . 
 com 
 / 
 googleapis 
 / 
 python 
 - 
 spanner 
 - 
 sqlalchemy 
 . 
 git 
 cd 
  
 python 
 - 
 spanner 
 - 
 sqlalchemy 
 python 
  
 setup 
 . 
 py 
  
 install 
 

As authentication for the Spanner dialect for SQLAlchemy, provide the service account JSON credentials file location in the GOOGLE_APPLICATION_CREDENTIALS environment variable. Otherwise, the dialect can also use the default credentials set in the gcloud CLI application.

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 consult the reference documentation on GitHub.

What's next

Create a Mobile Website
View Site in Mobile | Classic
Share by: