Skip to main content

googlesql

This package contains the GoogleSQL protobuf schemas and generated Python bindings for the local service.

Install the protobuf-only package with:

uv add googlesql

Install the generated gRPC client bindings with:

uv add 'googlesql[grpc]'

The generated modules are available under googlesql.local_service. For example:

import grpc

from googlesql.local_service import local_service_pb2
from googlesql.local_service import local_service_pb2_grpc

channel = grpc.insecure_channel("127.0.0.1:50051")
client = local_service_pb2_grpc.GoogleSqlLocalServiceStub(channel)
response = client.GetAnalyzerOptions(
    local_service_pb2.AnalyzerOptionsRequest()
)

The package follows the current checkout's local_service.proto API. It does not include the GoogleSQL service implementation.

Analyzing with a client-owned catalog

googlesql.client_catalog drives the AnalyzeWithClientCatalog stream: the client sends one AnalyzeRequest, the server sends back each catalog lookup it needs while analyzing, the client answers from its own catalog, and the server finishes with the resolved AST. Lookup answers use the JSON object formats from googlesql_service/CATALOG_PROTOCOL.md section 6. The module needs the grpc extra.

import grpc

from googlesql import client_catalog
from googlesql.local_service import local_service_pb2
from googlesql.local_service import local_service_pb2_grpc


class Catalog:
  def lookup(self, object_kind, name_path):
    if object_kind == "table" and list(name_path) == ["orders"]:
      return {
          "kind": "table",
          "name": "orders",
          "full_name": "project.dataset.orders",
          "columns": [{"name": "id", "type": {"typeKind": "TYPE_INT64"}}],
      }
    return None  # not found


channel = grpc.insecure_channel("127.0.0.1:50051")
stub = local_service_pb2_grpc.GoogleSqlLocalServiceStub(channel)
request = local_service_pb2.AnalyzeRequest(sql_statement="SELECT id FROM orders")
response = client_catalog.analyze_with_client_catalog(
    stub, request, Catalog(), timeout=30
)

A lookup may return None for a missing object or raise client_catalog.CatalogLookupError(message, status_code) to report a typed failure. Analysis failures raise client_catalog.ClientCatalogAnalyzeError with the gRPC status code and message. Pass timeout so a stalled server cannot block the caller indefinitely; it bounds the gRPC call but does not interrupt a lookup that is still running, so a catalog backed by a remote service should enforce its own timeouts.

Regenerating bindings

From the repository root, update the copied proto closure and generated files with:

uv run --project py/googlesql python tools/update_python_client.py

To verify that committed files are up to date without changing the worktree:

uv run --project py/googlesql python tools/update_python_client.py --check

The updater uses the repository's Python template generators and Buf. Bazel is not required for Python client generation.

Metadata

Release files for googlesql 0.2.0

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

Source distribution (sdist)

Source distribution for googlesql 0.2.0
File Size Uploaded
googlesql-0.2.0.tar.gz 508.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for googlesql 0.2.0
File Interpreter ABI Platform
googlesql-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.1 MB

Release files / googlesql-0.2.0.tar.gz

Download URL googlesql-0.2.0.tar.gz
Size 508.4 kB
Tags Source
SHA-256 checksum
How to use checksums
58e69a559b7d0a92fbb14ecc9e9082cb0faa0d10456f23bf87312f6b24846c90
BLAKE2b-256 checksum
How to use checksums
2b93ead7c1e556bbc11e8e23105e5de3f1380c47c49a1cc2fb587c3bc3f4362b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.22

Release files / googlesql-0.2.0-py3-none-any.whl

Download URL googlesql-0.2.0-py3-none-any.whl
Size 567.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
038ea1a7a8ef7f5fcf5bd5d385e386d8c399f717ae8d9ab1e99d8bb21bed65e8
BLAKE2b-256 checksum
How to use checksums
c9f6e11b423b243c8a8670de6f943b2ae5bcd8c7138280b68b7e3418c0e05a8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.22

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

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