Skip to main content

Python SDK for the UDB DataBroker gRPC API

Project description

UDB Python SDK

udb-client is the Python SDK for the UDB DataBroker gRPC API. It ships the generated protobuf bindings plus a small sync/async client that injects UDB metadata, builds common CRUD/vector/blob requests, and exposes the raw generated stub for every broker RPC.

Install

pip install udb-client==0.3.0

For local development from this repo, prefer uv:

cd sdk/python
uv sync --extra dev
uv run python scripts/generate_protos.py
uv run pytest
uv run pyrefly check

The same flow with pip:

cd sdk/python
python -m pip install -e ".[dev]"
python scripts/generate_protos.py
pytest
pyrefly check

Basic CRUD

from udb_client import Metadata, UdbClient, decode_records

meta = Metadata(
    tenant_id="tenant-1",
    user_id="user-1",
    purpose="billing.demo",
    correlation_id="demo-001",
    scopes=("udb:read", "udb:write"),
    service_identity="python.example",
    project_id="billing",
)

with UdbClient("127.0.0.1:50051", meta) as udb:
    udb.warmup()

    udb.upsert(
        message_type="acme.billing.v1.Customer",
        record={
            "customer_id": "cus_001",
            "tenant_id": "tenant-1",
            "name": "Ada Lovelace",
            "email": "ada@example.com",
        },
        conflict_fields=("customer_id",),
        return_record=True,
    )

    rows = udb.select(
        message_type="acme.billing.v1.Customer",
        filter={"customer_id": "cus_001"},
        limit=1,
    )
    print(decode_records(rows))

    udb.delete(
        message_type="acme.billing.v1.Customer",
        filter={"customer_id": "cus_001"},
    )

Async

from udb_client import Metadata, UdbAsyncClient

async with UdbAsyncClient("127.0.0.1:50051", Metadata(
    tenant_id="tenant-1",
    purpose="billing.worker",
    correlation_id="job-42",
    scopes=("udb:read", "udb:write"),
    service_identity="python.worker",
    project_id="billing",
)) as udb:
    await udb.upsert(
        message_type="acme.billing.v1.Customer",
        record={"customer_id": "cus_002", "tenant_id": "tenant-1"},
        conflict_fields=("customer_id",),
    )

Full API Access

The generated protobuf modules are included:

from udb.entity.v1 import types_pb2
from udb.services.v1 import data_broker_pb2_grpc

For broker APIs without a convenience method, use client.call("RpcName", request) for unary RPCs with metadata/error handling, or client.stub for raw streaming and advanced calls.

Optional Pydantic Models

Install the pydantic extra when you want request validation and editor-friendly models:

pip install "udb-client[pydantic]==0.3.0"
from udb_client import UdbClient
from udb_client.models import MetadataModel, UpsertCommand

meta = MetadataModel(
    tenant_id="tenant-1",
    purpose="billing.demo",
    correlation_id="demo-001",
    scopes=("udb:write",),
    project_id="billing",
).to_metadata()

command = UpsertCommand(
    message_type="acme.billing.v1.Customer",
    record={"customer_id": "cus_001", "tenant_id": "tenant-1"},
    conflict_fields=("customer_id",),
)

with UdbClient("127.0.0.1:50051", meta) as udb:
    udb.upsert(command.to_proto())

Regenerate Protobuf Bindings

Run this after changing files under proto/udb:

cd sdk/python
python -m pip install -e ".[dev]"
python scripts/generate_protos.py

Generated udb/.../*_pb2.py, *_pb2_grpc.py, and *.pyi files are committed so pip users do not need grpcio-tools.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

udb_client-0.3.0.tar.gz (209.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

udb_client-0.3.0-py3-none-any.whl (327.9 kB view details)

Uploaded Python 3

File details

Details for the file udb_client-0.3.0.tar.gz.

File metadata

  • Download URL: udb_client-0.3.0.tar.gz
  • Upload date:
  • Size: 209.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for udb_client-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c0bd1d42b929b04df382c236dd9371b31a800ffe6e0ba7f9eeb60beb4ecedf6a
MD5 4e653a9a4420d934a860c7a069e0799d
BLAKE2b-256 355b5093707a410841ccd75cc18855c676f40fe577e10efa8c10f492d137c1d3

See more details on using hashes here.

File details

Details for the file udb_client-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: udb_client-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 327.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for udb_client-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4909a482b473490aaecf7ba1fdfe4de2d9903d1420eadac681dbec8e7d6ff866
MD5 3b779a33621ae632adea69ff1a3fd6ed
BLAKE2b-256 77b2592081d9562f9f9b156de63a9d038155dcce0c856bbd036043b67d8ebb57

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page