---
title: "Stream"
description: "This page lists the Python SDK names for Streams."
canonical_url: "https://docs.superdurable.io/reference/python/stream/"
source: "docs/reference/python/stream.mdx"
locale: "en"
---

# Stream

This page lists the Python SDK names for [Streams](https://docs.superdurable.io/concepts/primitives/stream.md).
The doc comment of each API gives its parameters, defaults, and errors. Read
them in the [Python SDK API reference](https://docs.superdurable.io/reference/python.md#api-reference).

<a id="api-names"></a>

## API names

| Task                                     | Python API                                                            | Dex behavior                                                                                             |
| ---------------------------------------- | --------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
| Define a Stream and its byte capacity    | **Stream**, with **stream_capacity_bytes**                            | [Capacity and trimming](https://docs.superdurable.io/reference/server/runtime-data.md#stream-capacity)   |
| Declare it in the Flow                   | **PersistenceSchema.of**, returned from **get_persistence_schema**    | [Flow definition](https://docs.superdurable.io/reference/python/flow.md#flow-definition)                 |
| Write a message from a Step              | **Stream.write**                                                      | [Write semantics](https://docs.superdurable.io/reference/server/runtime-data.md#stream-write-semantics)  |
| Write text chunks in batches from a Step | **Stream.buffered_text**                                              | [Buffer text chunks](https://docs.superdurable.io/reference/server/runtime-data.md#stream-buffered-text) |
| Write a message from a Client            | **Client.write_stream**                                               | [Write semantics](https://docs.superdurable.io/reference/server/runtime-data.md#stream-write-semantics)  |
| Read the next message                    | **Client.read_stream**, with the **resume_token** of the last message | [Resumable reads](https://docs.superdurable.io/reference/server/runtime-data.md#stream-resumable-reads)  |
| List retained messages, newest first     | **Client.list_stream_messages**                                       | [List messages](https://docs.superdurable.io/reference/server/runtime-data.md#stream-listing)            |

**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.

<a id="example"></a>

## Example

Example: [examples/python/dex_examples/primitives/stream/stream_flow.py](https://github.com/superdurable/dex/tree/main/examples/python/dex_examples/primitives/stream/stream_flow.py)
