Skip to main content
Sifr’s networking stack is a native async substrate built on Rust’s async I/O primitives and the Rustls TLS library. It is not a compatibility shim over CPython’s socket, ssl, or http modules — those bare names are rejected with a diagnostic and the correct sifr.* replacement is suggested. This page covers the four public networking modules and how they compose.

Module Map

The following CPython-shaped imports are rejected in Sifr:

TCP with sifr.net

connect_tcp opens an async TCP stream to a remote address. listen_tcp binds a local port and returns a listener that accepts incoming connections:
Network operations consume Sifr’s concurrency runtime for cancellation, deadlines, and backpressure. Use task.scope() or task.timeout() from sifr.task to bound the lifetime of network operations. See Concurrency Overview for the structured task model, and Concurrency API for the full sifr.task surface.

TLS with sifr.tls

Wrap a TCP connection in TLS using a client configuration built from a CA certificate bundle:
TLS is backed by Rustls, which enforces modern cipher suites and certificate validation by default. There is no API to disable certificate verification.

HTTP Substrate with sifr.http

sifr.http provides the typed HTTP protocol layer: request and response heads, header maps, body streams, and cookie parsing. This is a substrate API — it gives you the building blocks rather than a full client or server framework.

Headers

Build a HeaderMap from a list of (name, value) pairs using headers_from_pairs:

Request and Response Heads

Construct typed request and response heads with request_head and response_head:

Body Streams

BodyStream lets you collect a response body with an explicit size limit, preventing runaway memory growth from oversized payloads:
Parse the Cookie header into a list of (name, value) tuples:

Full HTTP Substrate Demo

The following is the complete HTTP substrate demo from the Sifr repository:

URL Parsing with sifr.url

Parse and decompose URLs with sifr.url:
Query parameters come back as typed key-value pairs. Percent-encoding and decoding are handled automatically for standard ASCII-safe characters.
Non-ASCII URL encodings (e.g., IDNA hostname canonicalization) are currently blocked on text/i18n Unicode alignment work and are not available in this release.

What Is Not in This Release

The networking substrate is production-ready for TCP, TLS, and HTTP/1.1 and HTTP/2 transport. The following features are deferred to future capabilities:
  • High-level HTTP client (retries, auth, compression, redirects)
  • Server routing, middleware, and request extractors
  • WebSocket and HTTP/3 support
  • SO_REUSEPORT and multi-worker serving