Stream
查看 MarkdownThis page lists the Python SDK names for Streams. The doc comment of each API gives its parameters, defaults, and errors. Read them in the Python SDK API reference.
API names
| Task | Python API | Dex behavior |
|---|---|---|
| Define a Stream and its byte capacity | Stream, with stream_capacity_bytes | Capacity and trimming |
| Declare it in the Flow | PersistenceSchema.of, returned from get_persistence_schema | Flow definition |
| Write a message from a Step | Stream.write | Write semantics |
| Write text chunks in batches from a Step | Stream.buffered_text | Buffer text chunks |
| Write a message from a Client | Client.write_stream | Write semantics |
| Read the next message | Client.read_stream, with the resume_token of the last message | Resumable reads |
| List retained messages, newest first | Client.list_stream_messages | List messages |
Stream.write works in wait_for, execute, and the Flow timeout handler. An RPC handler cannot write a Stream. In a synchronous handler, Stream.write returns a StepOutput that the handler must yield. In an asynchronous handler, it enqueues the message and returns nothing.
Example
Example: examples/python/dex_examples/primitives/stream/stream_flow.py