Skip to main content

SPANNERLIB-PYTHON: A High-Performance Python Wrapper for the Go Spanner Client Shared lib

NOTICE: This is an internal library that can make breaking changes without prior notice.

Introduction

The spannerlib-python wrapper provides a high-performance, idiomatic Python interface for Google Cloud Spanner by wrapping the official Go Client Shared library.

The Go library is compiled into a C-shared library, and this project calls it directly from Python, aiming to combine Go's performance with Python's ease of use.

Installation

To install the library, use pip:

pip install spannerlib-python

Usage

Here is a simple example of how to use the library to execute a SQL query.

1. Import the library

from google.cloud.spannerlib import Pool
from google.cloud.spanner_v1 import ExecuteSqlRequest

2. Create a connection pool

Initialize the pool with your database connection string.

connection_string = "projects/<your-project>/instances/<your-instance>/databases/<your-database>"
pool = Pool.create_pool(connection_string)

3. Create a connection

conn = pool.create_connection()

4. Execute a query

Use ExecuteSqlRequest to specify your SQL query.

sql = "SELECT 'Hello, World!' as greeting"
request = ExecuteSqlRequest(sql=sql)

# Execute the query
rows = conn.execute(request)

# Iterate over the results
while True:
    row = rows.next()
    if row is None:
        break
    # row is a google.protobuf.struct_pb2.ListValue
    print(row.values[0].string_value)

# Close the rows object when done
rows.close()

5. Cleanup

Always close the connection and pool to release resources.

conn.close()
pool.close()

Using Context Managers

You can also use the with statement to automatically manage resources (close connections and pools).

from google.cloud.spannerlib import Pool
from google.cloud.spanner_v1 import ExecuteSqlRequest

connection_string = "projects/<your-project>/instances/<your-instance>/databases/<your-database>"

# Pool and Connection are context managers
with Pool.create_pool(connection_string) as pool:
    with pool.create_connection() as conn:
        sql = "SELECT 'Hello, World!' as greeting"
        request = ExecuteSqlRequest(sql=sql)
        
        # Rows/Results are also context managers
        with conn.execute(request) as rows:
            for row in iter(rows.next, None):
                print(row.values[0].string_value)
# Resources are automatically closed here

Metadata

Release files for spannerlib-python 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spannerlib-python 0.1.1
File Size Uploaded Provenance Actions
spannerlib_python-0.1.1.tar.gz 78.7 MB With provenance Details for spannerlib_python-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for spannerlib-python 0.1.1
File Interpreter ABI Platform Actions
spannerlib_python-0.1.1-py3-none-any.whl Python 3 none any Details for spannerlib_python-0.1.1-py3-none-any.whl

Total release size: 157.9 MB

Release files / spannerlib_python-0.1.1.tar.gz

Download URL spannerlib_python-0.1.1.tar.gz
Size 78.7 MB
Tags Source
SHA-256 checksum
How to use checksums
4a835600b83895619f6bba2f12db045390da55838d8c83b00e0a137a2257af54
BLAKE2b-256 checksum
How to use checksums
1296b4383799cfabe04e2d34cf44215620d4f0ffb7b31ace2ab6c45a90526583
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 9, 2025.

Transparency log

Release files / spannerlib_python-0.1.1-py3-none-any.whl

Download URL spannerlib_python-0.1.1-py3-none-any.whl
Size 79.2 MB
Tags Python 3
SHA-256 checksum
How to use checksums
75398588c3d3d3937aac20a1a31f3e6c85f89a7aece5b31c370858f74d91298d
BLAKE2b-256 checksum
How to use checksums
fc0518b5cc803379b9d40a0105e76114a7ef9d3f58ff06bb517127f1b57c8b00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 9, 2025.

Transparency log

Security for spannerlib-python 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for spannerlib_python-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 9, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page