Search

Lib.rs

› Network programming | Asynchronous
#server-sent-events #http-client #sse

sse-stream

Conversion between http body and sse stream

by 4t145 and 2 contributors

  • Install
  • API reference
  • GitHub repo (4t145)

9 releases

0.2.3 Apr 28, 2026
0.2.2 Apr 10, 2026
0.2.1 Jun 18, 2025
0.2.0 May 18, 2025
0.1.3 Mar 22, 2025

#214 in Network programming

Download history 156022/week @ 2026-01-15 175476/week @ 2026-01-22 207698/week @ 2026-01-29 284534/week @ 2026-02-05 254404/week @ 2026-02-12 320941/week @ 2026-02-19 318659/week @ 2026-02-26 399172/week @ 2026-03-05 395307/week @ 2026-03-12 327975/week @ 2026-03-19 293714/week @ 2026-03-26 315757/week @ 2026-04-02 336234/week @ 2026-04-09 355684/week @ 2026-04-16 353072/week @ 2026-04-23 355739/week @ 2026-04-30

1,455,241 downloads per month
Used in 54 crates (12 directly)

MIT/Apache

28KB
551 lines

SSE Stream

Crates.io Version Release status docs.rs

A SSE decoder/encoder for Http body

Decode

# use sse_stream::SseStream;
# use http_body_util::Full;
# use bytes::Bytes;
# use futures_util::StreamExt;
const SSE_BODY: &str =
r#"
retry: 1000
event: userconnect
data: {"username": "bobby", "time": "02:33:48"}

data: Here's a system message of some kind that will get used
data: to accomplish some task.
"#;

let body = Full::<Bytes>::from(SSE_BODY);
let mut sse_body = SseStream::new(body);
async {
    while let Some(sse) = sse_body.next().await {
        println!("{:?}", sse.unwrap());
    }
};

Encode

# use std::convert::Infallible;
# use futures_util::StreamExt;
# use sse_stream::{Sse, SseBody};

let stream = futures_util::stream::iter([
    Sse::default().event("1").data("....."),
    Sse::default().event("2").data("....."),
    Sse::default().event("3").data("....."),
])
.map(Result::<Sse, Infallible>::Ok);
let body = SseBody::new(stream);

Dependencies

~1–3MB
~35K SLoC

  • bytes
  • futures-util
  • http-body 1.0
  • http-body-util
  • pin-project-lite
  • optional tracing
  • dev anyhow
  • dev axum 0.8+tracing
  • dev hyper 1.0+client+http1
  • dev hyper-util+tokio
  • dev reqwest 0.12+stream
  • dev serde+derive
  • dev tokio+full
  • dev tokio-util+io
  • dev tracing-subscriber+env-filter+std+fmt
See also: eventsource-stream, eventsource-client, tokio-rustls, reqwest-middleware, turul-http-mcp-server, reqwest-eventsource, salvo-serde-util, asynchronous-codec, stream-cancel, tower-service, hyper-tls

Lib.rs is an unofficial list of Rust/Cargo crates, created by kornelski. It contains data from multiple sources, including heuristics, and manually curated data. Content of this page is not necessarily endorsed by the authors of the crate. This site is not affiliated with nor endorsed by the Rust Project. If something is missing or incorrect, please file a bug.