Skip to content

Conversation

@bhatt4982
Copy link
Contributor

No description provided.

@bhatt4982 bhatt4982 requested a review from a team as a code owner December 1, 2025 11:15
@gemini-code-assist
Copy link

Summary of Changes

Hello @bhatt4982, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request lays the foundational groundwork for a new Python client library, spannerlib-python, designed to offer a high-performance interface to Google Cloud Spanner by leveraging the official Go client's shared library. It meticulously constructs the necessary FFI layer to bridge Python and Go, ensuring safe and efficient communication and resource management. The introduction of core abstractions like AbstractLibraryObject, Pool, Connection, and especially the Rows class, provides a structured and idiomatic Python experience for interacting with Spanner, backed by extensive testing and build automation.

Highlights

  • New Python Wrapper: Introduces spannerlib-python, a high-performance Python wrapper for the Go Spanner client shared library, aiming to combine Go's performance with Python's ease of use.
  • Foreign Function Interface (FFI) Layer: Establishes a robust FFI using ctypes for seamless interaction between Python and the Go shared library, including custom Message, GoString, and GoSlice types for data exchange and memory management.
  • Resource Management: Implements AbstractLibraryObject as a base class for native resources, providing context manager support (with statement) and __del__ finalizers to ensure proper cleanup and prevent memory leaks.
  • Core Client Classes: Adds Pool and Connection classes to manage database connections and execute various Spanner operations like SQL queries, batch DML, and mutations.
  • Rows Class for Results: Introduces the Rows class to efficiently handle query results, providing methods for iterating through rows, accessing result set metadata, and retrieving update counts.
  • Comprehensive Testing & Build Infrastructure: Includes a full suite of unit and system tests, along with Nox automation and a build-shared-lib.sh script, to validate the wrapper's functionality across different operating systems and against a Spanner emulator.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the core Python wrapper for the Spanner Go shared library, including the Pool, Connection, and Rows classes, along with their ctypes-based internal implementation and a comprehensive set of unit and system tests. The overall structure is well-designed, particularly the use of an abstract base class for resource management and the safety nets for handling unclosed resources. My review focuses on improving error handling consistency, clarifying documentation and log messages, and making the code more robust by avoiding silent failures and brittle exception checks. These changes will enhance the library's maintainability and developer experience.

@bhatt4982
Copy link
Contributor Author

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This is a comprehensive pull request that introduces a new Python wrapper for the Spanner Go library. The code is well-structured, with a clear separation of concerns between the FFI layer, public-facing objects, and utility components. The use of abstract base classes for resource management, context managers, and finalizers (__del__) to warn about unclosed resources demonstrates a strong focus on correctness and memory safety, which is crucial for a C-extension wrapper. The unit and system tests are thorough and provide good coverage. I've identified a few areas for improvement, mainly concerning a potential build script issue, consistency in error handling, and a logic bug in update_count. Overall, this is an excellent foundation for the new library.

@bhatt4982 bhatt4982 changed the base branch from main to psd-05-exec December 3, 2025 13:42
bhatt4982 and others added 2 commits December 4, 2025 18:23
…ion class and relevant tests... (#662)

* feat: Add transaction management with `begin_transaction`, `commit`, and `rollback` methods and their respective tests.

* feat: add system and unit tests for transaction mutation writes, including commit and rollback scenarios.
… unavailable and updates the corresponding test.
@bhatt4982 bhatt4982 merged commit 8501db2 into psd-05-exec Dec 4, 2025
28 checks passed
@bhatt4982 bhatt4982 deleted the psd-06-rows branch December 4, 2025 13:03
bhatt4982 added a commit that referenced this pull request Dec 4, 2025
…ecuteBatch and WriteMutation methods and relevant tests... (#660)

* feat: Introduce `Rows` class and add `execute`, `execute_batch`, and `write_mutations` methods to `Connection`.

* feat: Add SQL execution, batch DML, and mutation writing methods to Connection and expose Rows object.

* Chore: Python-Spanner-Driver - Added Rows class, its methods and relevant tests... (#661)

* test: add system tests for query, batch DML, and mutation operations, including emulator setup.

* feat: Add `next()`, `metadata()`, `result_set_stats()`, and `update_count()` methods to the `Rows` class for fetching data and statistics, including unit tests.

* test: Add system tests for `Rows` class covering metadata, stats, update count, and row iteration.

* Chore: Python-Spanner-Driver - Added transaction functions in Connection class and relevant tests... (#662)

* feat: Add transaction management with `begin_transaction`, `commit`, and `rollback` methods and their respective tests.

* feat: add system and unit tests for transaction mutation writes, including commit and rollback scenarios.

* feat: `update_count`  returns -1 instead of 0 when row count stats are unavailable and updates the corresponding test.

* refactor: remove direct Pool argument from Rows constructor and access via Connection.

* feat: Add `IF NOT EXISTS` to `CREATE TABLE` and `IF EXISTS` to `DROP TABLE` statements, removing explicit exception handling.

* feat: `write_mutations` now returns `None` for buffered mutations, updating its return type and related tests.
bhatt4982 added a commit that referenced this pull request Dec 4, 2025
…sts (#659)

* feat: introduce Connection class and enable Pool to create and manage connections

* Chore: Python-Spanner-Driver | Spannerlib Wrapper | Added Execute, ExecuteBatch and WriteMutation methods and relevant tests... (#660)

* feat: Introduce `Rows` class and add `execute`, `execute_batch`, and `write_mutations` methods to `Connection`.

* feat: Add SQL execution, batch DML, and mutation writing methods to Connection and expose Rows object.

* Chore: Python-Spanner-Driver - Added Rows class, its methods and relevant tests... (#661)

* test: add system tests for query, batch DML, and mutation operations, including emulator setup.

* feat: Add `next()`, `metadata()`, `result_set_stats()`, and `update_count()` methods to the `Rows` class for fetching data and statistics, including unit tests.

* test: Add system tests for `Rows` class covering metadata, stats, update count, and row iteration.

* Chore: Python-Spanner-Driver - Added transaction functions in Connection class and relevant tests... (#662)

* feat: Add transaction management with `begin_transaction`, `commit`, and `rollback` methods and their respective tests.

* feat: add system and unit tests for transaction mutation writes, including commit and rollback scenarios.

* feat: `update_count`  returns -1 instead of 0 when row count stats are unavailable and updates the corresponding test.

* refactor: remove direct Pool argument from Rows constructor and access via Connection.

* feat: Add `IF NOT EXISTS` to `CREATE TABLE` and `IF EXISTS` to `DROP TABLE` statements, removing explicit exception handling.

* feat: `write_mutations` now returns `None` for buffered mutations, updating its return type and related tests.
bhatt4982 added a commit that referenced this pull request Dec 4, 2025
…and relevant tests (#658)

* feat: Introduce AbstractLibraryObject and Pool modules with their unit and system tests, replacing placeholder tests.

* Chore: Python-Spanner-Driver - Added Connection class and relevant tests (#659)

* feat: introduce Connection class and enable Pool to create and manage connections

* Chore: Python-Spanner-Driver | Spannerlib Wrapper | Added Execute, ExecuteBatch and WriteMutation methods and relevant tests... (#660)

* feat: Introduce `Rows` class and add `execute`, `execute_batch`, and `write_mutations` methods to `Connection`.

* feat: Add SQL execution, batch DML, and mutation writing methods to Connection and expose Rows object.

* Chore: Python-Spanner-Driver - Added Rows class, its methods and relevant tests... (#661)

* test: add system tests for query, batch DML, and mutation operations, including emulator setup.

* feat: Add `next()`, `metadata()`, `result_set_stats()`, and `update_count()` methods to the `Rows` class for fetching data and statistics, including unit tests.

* test: Add system tests for `Rows` class covering metadata, stats, update count, and row iteration.

* Chore: Python-Spanner-Driver - Added transaction functions in Connection class and relevant tests... (#662)

* feat: Add transaction management with `begin_transaction`, `commit`, and `rollback` methods and their respective tests.

* feat: add system and unit tests for transaction mutation writes, including commit and rollback scenarios.

* feat: `update_count`  returns -1 instead of 0 when row count stats are unavailable and updates the corresponding test.

* refactor: remove direct Pool argument from Rows constructor and access via Connection.

* feat: Add `IF NOT EXISTS` to `CREATE TABLE` and `IF EXISTS` to `DROP TABLE` statements, removing explicit exception handling.

* feat: `write_mutations` now returns `None` for buffered mutations, updating its return type and related tests.
bhatt4982 added a commit that referenced this pull request Dec 4, 2025
…dle spannerlib library interaction (#657)

* feat: Add initial Python wrapper for Spanner library,
including internal message structures, error handling,
and a protocol definition.

* refactor: Introduce `_load_library` for library initialization, remove `_get_lib_path`, and update related tests.

* Chore: Python-Spanner-Driver | Spannerlib Wrapper | Added Pool class and relevant tests (#658)

* feat: Introduce AbstractLibraryObject and Pool modules with their unit and system tests, replacing placeholder tests.

* Chore: Python-Spanner-Driver - Added Connection class and relevant tests (#659)

* feat: introduce Connection class and enable Pool to create and manage connections

* Chore: Python-Spanner-Driver | Spannerlib Wrapper | Added Execute, ExecuteBatch and WriteMutation methods and relevant tests... (#660)

* feat: Introduce `Rows` class and add `execute`, `execute_batch`, and `write_mutations` methods to `Connection`.

* feat: Add SQL execution, batch DML, and mutation writing methods to Connection and expose Rows object.

* Chore: Python-Spanner-Driver - Added Rows class, its methods and relevant tests... (#661)

* test: add system tests for query, batch DML, and mutation operations, including emulator setup.

* feat: Add `next()`, `metadata()`, `result_set_stats()`, and `update_count()` methods to the `Rows` class for fetching data and statistics, including unit tests.

* test: Add system tests for `Rows` class covering metadata, stats, update count, and row iteration.

* Chore: Python-Spanner-Driver - Added transaction functions in Connection class and relevant tests... (#662)

* feat: Add transaction management with `begin_transaction`, `commit`, and `rollback` methods and their respective tests.

* feat: add system and unit tests for transaction mutation writes, including commit and rollback scenarios.

* feat: `update_count`  returns -1 instead of 0 when row count stats are unavailable and updates the corresponding test.

* refactor: remove direct Pool argument from Rows constructor and access via Connection.

* feat: Add `IF NOT EXISTS` to `CREATE TABLE` and `IF EXISTS` to `DROP TABLE` statements, removing explicit exception handling.

* feat: `write_mutations` now returns `None` for buffered mutations, updating its return type and related tests.

* Update spannerlib/wrappers/spannerlib-python/spannerlib-python/google/cloud/spannerlib/internal/message.py

Co-authored-by: Knut Olav Løite <koloite@gmail.com>

* feat: Remove Python 3.8 fallback for `importlib.resources` and few docstring update

* feat: Enhance SpannerLibError messages to include gRPC status names and add corresponding tests.

* test: update SpannerLibError repr test message and code values

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Knut Olav Løite <koloite@gmail.com>
bhatt4982 added a commit that referenced this pull request Dec 4, 2025
* chore: Create setup for SpannerLib-Python project

* Chore: Python-Spanner-Driver | Spannerlib Wrapper | Added code to handle spannerlib library interaction (#657)

* feat: Add initial Python wrapper for Spanner library,
including internal message structures, error handling,
and a protocol definition.

* Chore: Python-Spanner-Driver | Spannerlib Wrapper | Added Pool class and relevant tests (#658)

* feat: Introduce AbstractLibraryObject and Pool modules with their unit and system tests, replacing placeholder tests.

* Chore: Python-Spanner-Driver - Added Connection class and relevant tests (#659)

* feat: introduce Connection class and enable Pool to create and manage connections

* Chore: Python-Spanner-Driver | Spannerlib Wrapper | Added Execute, ExecuteBatch and WriteMutation methods and relevant tests... (#660)

* feat: Introduce `Rows` class and add `execute`, `execute_batch`, and `write_mutations` methods to `Connection`.

* feat: Add SQL execution, batch DML, and mutation writing methods to Connection and expose Rows object.

* Chore: Python-Spanner-Driver - Added Rows class, its methods and relevant tests... (#661)

* test: add system tests for query, batch DML, and mutation operations, including emulator setup.

* feat: Add `next()`, `metadata()`, `result_set_stats()`, and `update_count()` methods to the `Rows` class for fetching data and statistics, including unit tests.

* test: Add system tests for `Rows` class covering metadata, stats, update count, and row iteration.

* Chore: Python-Spanner-Driver - Added transaction functions in Connection class and relevant tests... (#662)

* feat: Add transaction management with `begin_transaction`, `commit`, and `rollback` methods and their respective tests.

* feat: add system and unit tests for transaction mutation writes, including commit and rollback scenarios.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants