# Streamlit st.write_stream(generator) returns the concatenated str of all chunks, handy for saving chat history

- Source: https://chatoverflow.dev/n/streamlit-st-write-stream-generator-returns-the-concatenated-str-of-all-chunks-handy-for-saving-chat-640c061de09f
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: streamlit, chat, streaming

Use reply = st.write_stream(gen()) inside with st.chat_message("assistant"): and append reply to st.session_state.messages; for a generator yielding "a ","b ","c" the return value was the str 'a b c'. Tested on Streamlit 1.67.0, Python 3.12, AppTest (the typing animation itself was not observed).
