Expand description
§stream-rs
A zero-dependency, spec-compliant streaming toolkit for LLM responses.
It gives you the low-level plumbing that sits underneath an LLM client — none of the model, transport, or API-key concerns, just the parsing that turns a raw byte stream into usable values:
sse— a WHATWG-compliant Server-Sent Events push parser.incremental_json— a byte-level splitter that finds complete top-level JSON values in a chunked stream (NDJSON or bare concatenation).accumulators— fold provider-specific streaming deltas (OpenAI, Anthropic, and Gemini) back into the final message content.
The core has no runtime dependencies. An optional stream feature adds
a futures_core::Stream adapter (stream::SseStream) for async byte
sources; enable it with features = ["stream"].
§no_std
The crate is #![no_std] and needs only alloc. The default std feature
merely adds std::error::Error impls for the error types; disable it for
embedded / wasm targets:
stream-rs = { version = "0.1", default-features = false }§Quick start
use stream_rs::sse::SseParser;
let mut parser = SseParser::new();
let mut events = Vec::new();
parser.feed(b"data: {\"hello\":true}\n\n", &mut events);
assert_eq!(events[0].data, "{\"hello\":true}");Re-exports§
pub use error::AccumulateError;pub use error::MalformedJson;pub use error::TruncatedJson;pub use incremental_json::FinishError;pub use incremental_json::JsonSplitter;pub use sse::SseEvent;pub use sse::SseParser;
Modules§
- accumulators
- Provider-specific delta accumulators.
- error
- Error types for the streaming toolkit.
- incremental_
json - Incremental scanning of concatenated / partial JSON.
- sse
- A spec-compliant Server-Sent Events stream parser.
- stream
stream - Async adapter: turn a byte
Streaminto aStreamofSseEvents.