Skip to content

[Python] Add stream_builder() - #1116

Closed
dimitrije-djordjevic-db wants to merge 1 commit into
mainfrom
effort/mux-streams-pyo3-builder
Closed

dimitrije-djordjevic-db wants to merge 1 commit into
mainfrom
effort/mux-streams-pyo3-builder

Conversation

@dimitrije-djordjevic-db

@dimitrije-djordjevic-db dimitrije-djordjevic-db commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Stack

  1. [Python] Add stream_builder() #1116 ← this PR
  2. [Python] Add multiplexed streams (Beta) #1117
  3. [Python] Add validate() and federated_auth() #1118

What changes are proposed in this pull request?

This PR adds ZerobusSdk.stream_builder() to the sync (zerobus.sdk.sync) and async (zerobus.sdk.aio) SDKs, mirroring the Rust SDK's stream_builder(). You set the table, the authentication (oauth(...) or headers_provider(...)), the record format (json(), compiled_proto(...), or avro(...)), and the stream settings, then call build(). It returns the same ZerobusStream as create_stream(), which does not change.

stream = (
    sdk.stream_builder()
    .table("catalog.schema.events")
    .oauth(client_id, client_secret)
    .compiled_proto(record_pb2.AirQuality.DESCRIPTOR.file.serialized_pb)
    .build()
)
for record in records:
    stream.ingest_record_offset(record)  # queues only; do not wait here
stream.flush()
stream.close()

Why: a builder keeps optional settings out of positional arguments and matches the Rust and Java SDKs. It is also the entry point for multiplexed streams, which the next PR in this stack adds as stream_builder()...multiplexed(n).

  • The builder collects settings in Python and hands them to the native layer as one internal StreamSettings object. Settings left unset are never forwarded, so the Rust core keeps its own defaults.
  • Missing or conflicting settings raise ValueError before anything is opened. The last auth setter and the last format setter win.
  • The setters shared with the persistent stream builder move into a common base class. The persistent builder's behavior and error messages are unchanged.
  • External-IdP federation stays on create_stream(auth=...) for now; a later PR in this stack adds it to the builder.
  • [Python] Add personal_access_token to the persistent stream builder #1073 also edits zerobus/sdk/shared/persistent.py, which this PR refactors; whichever merges second rebases onto the other.

Related: #163

How is this tested?

  • tests/test_stream_builder.py (runs in CI, no server): required settings, last-setter-wins for auth and format, setter input checks, a complete configuration for each record format reaching the native layer (an unreachable endpoint fails only after validation), the native layer's own one-auth-method check, and the public surface, in sync and async mode.
  • The existing persistent stream builder tests pass unchanged.

This pull request and its description were written by Isaac.

Add ZerobusSdk.stream_builder() to the sync and async SDKs, mirroring
the Rust SDK's stream_builder(): set the table, OAuth or a custom
headers provider, the JSON, protobuf, or Avro format, and stream
settings, then call build() for a ZerobusStream. create_stream() is
unchanged and remains the way to use external-IdP federation.

The setters it shares with the persistent stream builder move into a
common base class; the persistent builder's behavior and error messages
are unchanged.

Co-authored-by: Isaac <no-reply@databricks.com>
Signed-off-by: Dimitrije Đorđević <dimitrije.djordjevic@databricks.com>
@dimitrije-djordjevic-db

Copy link
Copy Markdown
Contributor Author

Superseded: Python opens multiplexed streams with create_multiplexed_stream instead of a stream builder. See #1224 and #1117.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant