aspanner
Asyncio Google Cloud Spanner Client, wrapped google-cloud-spanner to support aio calls, provide easy-to-use methods. This project exists because Spanner have no easy-to-use asyncio interface.
References:
- https://github.com/googleapis/python-spanner
- https://googleapis.dev/python/spanner/latest/index.html
- https://cloud.google.com/spanner/docs/samples
- https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.v1
Quick Start
-
Get the credentials JSON file from Google Cloud - IAM - Service Account - Keys, or run directly from permission granted VM, follow the tutorials from google.
-
Create Spanner instance, create database, and create test table.
CREATE TABLE tb_test_types ( id INT64 NOT NULL, data_str STRING(MAX), data_int INT64, data_float FLOAT64, data_bool BOOL, data_num NUMERIC, data_bytes BYTES(MAX), data_date DATE, data_time TIMESTAMP, data_array ARRAY<INT64>, data_json JSON, ) PRIMARY KEY(id);
-
Code test.py
async def test(): db = aspanner.Aspanner('google cloud project id', 'spanner instance name', 'database') cols = ('id', 'data_int') print(await db.insert('tb_test_types', cols, [(9, 999)])) print(await db.read('tb_test_types', cols, [(9,)])) print(await db.delete('tb_test_types', [(9,)])) print(await db.close()) asyncio.run(test())
-
Run in terminal.
pip install aspanner # if use credentials file export GOOGLE_APPLICATION_CREDENTIALS="/home/user/project-server-1234568-1234567890.json" python3 test.py
TODO
Retry now should be outside transaction with block, like: https://github.com/googleapis/google-cloud-python/blob/92465cbc4d9c0ba251838e9cd17f61d14b470e04/spanner/google/cloud/spanner_v1/session.py#L353
error in sql while JSON is array.
Release files for aspanner 0.6.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aspanner-0.6.1.tar.gz | 10.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aspanner-0.6.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.8 kB
Release files / aspanner-0.6.1.tar.gz
| Download URL | aspanner-0.6.1.tar.gz |
|---|---|
| Size | 10.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
df786fe3ba1a0bcdcf62ac5443b53f79e265c260c4974da3d16da926627fc2b5
|
|
BLAKE2b-256 checksum How to use checksums |
cf10610243d8269ebaf518d9884458e85eaf7caa7aa0448122281fb9436ea14b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.26.0 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.10
|
Release files / aspanner-0.6.1-py3-none-any.whl
| Download URL | aspanner-0.6.1-py3-none-any.whl |
|---|---|
| Size | 11.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5346e17f8c9320c0aa0f2300389e4798b7724a25148aa4fb43612b97dc0d3ae0
|
|
BLAKE2b-256 checksum How to use checksums |
8557306beedb3cf09e76dbdb14a035bc827397810489b064f380a6f3d6b28fd5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.26.0 setuptools/56.0.0 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.8.10
|