reference
Stream methods
Stream methods on the LiveView base class, generated.
On this page
Stream methods on LiveView, generated from the framework manifest.
3 entries.
stream
self.stream(
name: str,
items: Any,
dom_id: Optional[Callable[[Any], str]] = None,
at: int = -1,
reset: bool = False,
limit: Optional[int] = None,
) -> djust.session_utils.Stream
| Parameter | Default and behavior |
|---|---|
name | Required. str. Stream name (used in template as streams.{name}) |
items | Required. Any. Iterable of items to add to the stream |
dom_id | Default: None. Optional[Callable[[Any], str]]. Function to generate DOM id from item (default: lambda x: x.id) |
at | Default: -1. int. Position to insert (-1 = end, 0 = beginning) |
reset | Default: False. bool. If True, clear existing items first |
limit | Default: None. Optional[int]. If set, emit a stream_prune op to cap the DOM element count. Items are pruned from the opposite edge of at: prepending (at=0) prunes the bottom; appending (at=-1) prunes the top. Used for bidirectional infinite scroll with dj-viewport-top/bottom. |
Initialize a stream collection. Items are available as streams.<name> in template.
stream_delete
self.stream_delete(name: str, item_or_id: Any) -> None
| Parameter | Default and behavior |
|---|---|
name | Required. str. |
item_or_id | Required. Any. |
Delete item from stream by object or ID.
stream_insert
self.stream_insert(name: str, item: Any, at: int = -1) -> None
| Parameter | Default and behavior |
|---|---|
name | Required. str. |
item | Required. Any. |
at | Default: -1. int. |
Insert item into stream. at=-1 appends, at=0 prepends.
Update a collection
def mount(self, request, **kwargs):
self.stream("messages", [{"id": 1, "text": "Welcome"}])
# Inside an event handler:
# self.stream_insert("messages", {"id": 2, "text": "Hello"}, at=0)
# self.stream_delete("messages", 1)
Give the collection a stable container ID and each row its stream DOM ID. Stream entries are cleared from server memory after rendering; the browser keeps the existing rows. See Large lists for the full template pattern and memory behavior.
Collection streams manage rows. For token-by-token text or partial HTML, see Streaming updates and Streaming render.