Express intent
Upload a file, upsert/select an entity, grant a role, subscribe to events. App code supplies business inputs, not internal table rows or protobuf plumbing.
Every SDK is generated from the same proto descriptor. Go, Python, TypeScript, Java, C# and
PHP are held to one cross-language conformance contract: identical metadata headers, credential handling,
authz-cache semantics, and refresh single-flight behavior; the Rust client ships typed tonic clients over
the same descriptor. udb sdk generate regenerates all seven from the embedded
descriptor set.
import os from udb_client.project import UdbProject with UdbProject.connect( target="127.0.0.1:50051", # data plane auth_target="127.0.0.1:50061", # control plane: data port + 10 api_key=os.environ["UDB_API_KEY"], # tenant + project come from the key ) as udb: pdf = open("invoice.pdf", "rb").read() udb.storage.upload_file("invoice.pdf", pdf, {"content_type": "application/pdf"}) udb.authz.allow_role("reader", "invoice", "Select") rows = udb.data.table("acme.billing.v1.Invoice").select(where={"status": "open"})
import ( "os" udb "github.com/fahara02/udb/sdk/go/udbclient" ) project, err := udb.Connect(ctx, udb.Config{ Target: "127.0.0.1:50051", // data plane AuthTarget: "127.0.0.1:50061", // control plane: data port + 10 Credentials: udb.Credentials{APIKey: os.Getenv("UDB_API_KEY")}, }) if err != nil { return err } defer project.Close() pdf, _ := os.ReadFile("invoice.pdf") _, _ = project.Storage.UploadFile(ctx, "invoice.pdf", pdf, udb.WithContentType("application/pdf")) invoices := project.Entity("acme.billing.v1.Invoice", udb.Key("invoice_id")) rows, _ := invoices.Select(ctx, map[string]any{"status": "open"})
import { readFile } from "node:fs/promises"; import { UdbProject } from "@udb_plus/sdk"; const udb = await UdbProject.connect({ target: "127.0.0.1:50051", // data plane authTarget: "127.0.0.1:50061", // control plane: data port + 10 tenantId: process.env.UDB_TENANT_ID!, // the key's own tenant UUID credentials: { apiKey: process.env.UDB_API_KEY }, }); const pdf = await readFile("invoice.pdf"); await udb.storage.uploadFile("invoice.pdf", pdf, { contentType: "application/pdf" }); await udb.authz.allowRole("reader", { resource: "invoice", action: "Select" });
use Fahara02\UdbLaravel\UdbProject; $udb = UdbProject::connect([ 'target' => '127.0.0.1:50051', // data plane 'authTarget' => '127.0.0.1:50061', // control plane: data port + 10 'credentials' => ['apiKey' => getenv('UDB_API_KEY')], ]); $pdf = file_get_contents('invoice.pdf'); $udb->storage()->uploadFile('invoice.pdf', $pdf, ['contentType' => 'application/pdf']); $udb->authz()->allowRole('reader', [ 'resource' => 'invoice', 'action' => 'Select', ]);
Either way the SDK takes the tenant from the verified principal, not from a header you set. An API key always acts as its own tenant; from 0.6.14 a tenant hint naming a different tenant is refused.
// Exchanged once via Authenticate{api_key} for a bearer the SDK // keeps fresh; the raw key is never sent on a call. const udb = await UdbProject.connect({ target: "127.0.0.1:50051", authTarget: "127.0.0.1:50061", tenantId: process.env.UDB_TENANT_ID!, // the key's own tenant UUID credentials: { apiKey: process.env.UDB_API_KEY }, });
// Login, verify, adopt the canonical tenant UUID, keep the bearer fresh. const udb = await UdbProject.connectEnterprise({ target: "127.0.0.1:50051", authTarget: "127.0.0.1:50061", tenantCode: "acme", // replaced by the tenant UUID after login username: "alice", password: process.env.UDB_PASSWORD!, });
Acting in a child tenant: policies of a parent tenant do not apply to its child tenants. A service
account that must work in another tenant gets a membership approved by that tenant, then exchanges its
home bearer with ExchangeServiceTokenForTenant for a token of at most 15 minutes, with no
refresh token. See service accounts.
The simple client is a thin workflow layer over served RPCs. It should make normal app code short, but it must not become a second protocol or move broker invariants into client conventions.
Upload a file, upsert/select an entity, grant a role, subscribe to events. App code supplies business inputs, not internal table rows or protobuf plumbing.
Own workflow helpers, byte transfer, token/session handling, typed errors, read-fence helpers, generated entity APIs, and exact sequence tests.
Own tenant/project authority, RLS, object placement, lifecycle state, idempotency, read-after-write guarantees, and fail-closed security decisions.
Descriptors and manifests drive SDK surfaces, operation kind, retry boundaries, entity metadata, native service recipes, and benchmark fixtures.
Two endpoints, always: the native control plane (auth, API keys, storage, authz, …) listens on its own port — loopback 127.0.0.1:50061, the data port + 10, unless the broker sets UDB_AUTH_GRPC_ADDR. The data-plane port answers UNIMPLEMENTED for native RPCs, so set authTarget / auth_target / AuthTarget to that listener. Add explicit scopes, purpose, deadlines, and raw generated RPC calls when building admin tools, benchmarks, or integrations that need exact protocol access.
The simple-client plan changes the docs priority: lead with workflow helpers for common product code, then show the raw generated clients as an escape hatch. These helpers are thin wrappers over served UDB RPCs and each has sequence tests so the SDK cannot hide proof reads or extra authority.
| Workflow | Use this surface | What the SDK does | What stays broker-owned |
|---|---|---|---|
| Upload bytes | storage.uploadFile / upload_file | Register upload, PUT to broker-minted URL, finalize. | Bucket choice, object key, quota, lifecycle state. |
| Download file | storage.downloadFile | Prefer one presigned URL call; stream bytes only when requested or needed. | Access decision, file metadata, object-store authorization. |
| CRUD records | data.table("invoice") / Entity(...) | Pack filters and records into the DataBroker request shape, decode native records. | RLS, tenant/project binding, backend routing, query execution. |
| Grant a role | authz.allowRole / allow_role | Emit one CreatePolicyRule call, no hidden list/get probe. | Caller authority, policy validity, audit, effective scopes. |
| Read after write | metadata.afterWrite(receipt) | Convert the write receipt into one read fence for the next read only. | Durable visibility, wait semantics, replica safety. |
| Events | events.subscribe(topic).ready() | Open the stream and expose an explicit readiness boundary before publish. | CDC envelope order, outbox delivery, broker-side matching. |
| Advanced/admin work | generated, Raw, service stubs | Expose exact RPC access without forcing every app through raw request bodies. | Protocol contract, method security, lifecycle rules. |
// Presigned URL path: one GetDownloadUrl RPC. const link = await udb.storage.downloadFile(fileId, { expiresInMinutes: 15 }); // Fallback path: one DownloadFile stream, reassembled by the SDK. const bytes = await udb.storage.downloadFile(fileId, { stream: true });
const write = await udb.data.upsert({ message_type: "Invoice", record_json: Buffer.from(JSON.stringify(invoice)), return_record: true, }); const receipt = udb.metadata.receiptFromResponse(write); const call = receipt ? udb.metadata.afterWrite(receipt) : undefined; const rows = await udb.data.table("Invoice").select({ where: { invoice_id: invoice.invoice_id }, call, });
All seven SDKs are generated from the same descriptor; the six application SDKs run the cross-language conformance suite. Publishing maturity differs by ecosystem, so the docs separate generated parity from package availability.
| Language | Generated surface | Install path | Primary facade |
|---|---|---|---|
| Go | DataBroker + native services | go get github.com/fahara02/udb/sdk/go@v0.6.25 | udbclient.Connect |
| Python | DataBroker + native services | pip install udb-client==0.6.25 | UdbProject.connect |
| TypeScript | DataBroker + native services | npm i @udb_plus/sdk@0.6.25 | UdbProject.connect |
| PHP | DataBroker + native services | composer require fahara02/udb-laravel:^0.6.25 | UdbProject::connect |
| C# | Generated client surface | dotnet add package Udb.Client --version 0.6.25 | generated client + metadata helpers |
| Rust | Typed tonic clients for DataBroker + native services | cargo add udb-client@0.6.13 | UdbClient + Metadata |
| Java | Generated client surface | build from checkout until Maven Central publishing lands | generated client + Spring-oriented helpers |
The same x-tenant-id, x-purpose, x-correlation-id, scopes, and project headers across the conformance SDKs. Credentials travel as authorization: Bearer: an API key is exchanged once through Authenticate{api_key} for a self-refreshing bearer and never sent raw.
Concurrent token refreshes collapse to one RefreshToken RPC, and the refreshed credential is hot-swapped into every outbound channel — verified per language.
A cross-language conformance runner asserts metadata, credential, authz-cache TTL, and policy-bundle-signature behavior; missing tooling or a failing suite is a release failure.
udb scaffold emits a starter project; udb sdk generate
regenerates all seven clients from the descriptor; udb proto export hands you the full proto tree.