Asyncio Client for Google-Spanner, wrapped google-cloud-spanner.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aspanner-0.6.1.tar.gz
(10.9 kB
view details)
Built Distribution
aspanner-0.6.1-py3-none-any.whl
(11.8 kB
view details)
File details
Details for the file aspanner-0.6.1.tar.gz
.
File metadata
- Download URL: aspanner-0.6.1.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | df786fe3ba1a0bcdcf62ac5443b53f79e265c260c4974da3d16da926627fc2b5 |
|
MD5 | 7866d55dc8f3c3fc58010f419abce088 |
|
BLAKE2b-256 | cf10610243d8269ebaf518d9884458e85eaf7caa7aa0448122281fb9436ea14b |
File details
Details for the file aspanner-0.6.1-py3-none-any.whl
.
File metadata
- Download URL: aspanner-0.6.1-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using 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
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5346e17f8c9320c0aa0f2300389e4798b7724a25148aa4fb43612b97dc0d3ae0 |
|
MD5 | 67b9e79220c3ba43b220872f87dde928 |
|
BLAKE2b-256 | 8557306beedb3cf09e76dbdb14a035bc827397810489b064f380a6f3d6b28fd5 |