# st.write_stream

Source: https://docs.streamlit.io/develop/api-reference/write-magic/st.write_stream

* Function signature:

   ```python
   st.write_stream(stream, *, cursor=None)
   ```

* Parameters:

   | name | type | default | description |
   |---|---|---|---|
   | stream | Callable, Generator, Iterable, OpenAI Stream, or LangChain Stream |  | The generator or iterable to stream. If you pass an async generator, Streamlit will internally convert it to a sync generator. If the generator depends on a cached object with async references, this can raise an error. Streamlit natively parses OpenAI streams (both the Chat Completions API and the Responses API) and LangChain streams.  Note To use additional LLM libraries, you can create a wrapper to manually define a generator function and include custom output parsing. |
   | cursor | str or None |  | A string to append to text as it's being written. If this is None (default), no cursor is shown. Otherwise, the string is rendered as Markdown and appears as a cursor at the end of the streamed text. For example, you can use an emoji, emoji shortcode, or Material icon. The first line of the cursor string can contain GitHub-flavored Markdown of the following types: Bold, Italics, Strikethroughs, Inline Code, Links, and Images. Images display like icons, with a max height equal to the font height. If you pass a multiline string, additional lines display after the text with the full Markdown rendering capabilities of st.markdown. See the body parameter of st.markdown for additional, supported Markdown directives. |

* Returns: str or list

    The full response. If the streamed output only contains text, this
is a string. Otherwise, this is a list of all the streamed objects.
The return value is fully compatible as input for st.write.

> **Tip**
>
> If your stream object is not compatible with `st.write_stream`, define a wrapper around your stream object to create a compatible generator function.
>
> ```python
> for chunk in unsupported_stream:
>     yield preprocess(chunk)
> ```
>
> For an example, see how we use [Replicate](https://replicate.com/docs/get-started/python) with [Snowflake Arctic](https://www.snowflake.com/en/data-cloud/arctic/) in [this code](https://github.com/streamlit/snowflake-arctic-st-demo/blob/0f0d8b49f328f72ae58ced2e9000790fb5e56e6f/simple_app.py#L58).
