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

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]"
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.2.0.tar.gz (186.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.2.0-py3-none-any.whl (299.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: udb_client-0.2.0.tar.gz
  • Upload date:
  • Size: 186.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.2.0.tar.gz
Algorithm Hash digest
SHA256 ffe651cf85d37f7815370f749e3281110882eb615afc17a0666566c8767bfb33
MD5 9a5e47ee077b8d520ad680aaf940a8be
BLAKE2b-256 8a9cb6c2437062c543721b6eddaef0738e1210e8568d34ee1d805cbcfc0c1ce3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: udb_client-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 299.5 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 65ec22eba17167b115115d7e7df20db3beaf6b3c37fc2a83370aa1be77d9c125
MD5 ff998221fc7ab94d8f27eae3b6c6feff
BLAKE2b-256 0fdbf9491bf742b2beb60ebe4d630b67215f962ab9cfe986b712949bfc8cc77c

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