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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file udb_client-0.2.1.tar.gz.
File metadata
- Download URL: udb_client-0.2.1.tar.gz
- Upload date:
- Size: 188.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d8624a8a356088e2b52c4900e24c812efc9a705b305ec61bbf716ed65be069d
|
|
| MD5 |
72eb033b86a1c7066f7e1adb5470eaad
|
|
| BLAKE2b-256 |
8ccd5d3a4f09cf7b0024a8f6def4db2c31287337b26000ca9d099e02a23a5837
|
File details
Details for the file udb_client-0.2.1-py3-none-any.whl.
File metadata
- Download URL: udb_client-0.2.1-py3-none-any.whl
- Upload date:
- Size: 300.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e0404d009552ab5df9af0da127a5779906787644a02ba372cb2d4af9135e814
|
|
| MD5 |
c3586eb6dadf53e4cf769d89af148051
|
|
| BLAKE2b-256 |
6e279a8a619c71b9f6caeb790ba676ed791e02bb5520c2a2877a470b00f4a336
|