Transports¶
lm15.transports — Minimal stdlib-only HTTP/1.1 transports.
Public API
TransportRequest, TransportResponse — transport-level request/response models StdlibTransport — sync transport (blocking, socket-based) StdlibAsyncTransport — async transport (asyncio-native) FetchTransport — async transport over the host's fetch (Pyodide: a page, a worker) Timeouts — per-operation timeouts (connect/read/write/pool) TransportError + subclasses
ConnectError
¶
Bases: TransportError
Failed to establish a TCP (or TLS) connection.
ConnectTimeout
¶
Bases: ConnectError
Connection establishment timed out.
ProtocolError
¶
Bases: TransportError
The server sent something that isn't valid HTTP/1.1.
ReadError
¶
Bases: TransportError
Failed to read from an open socket (EOF, reset, etc.).
TransportError
¶
Bases: Exception
Base transport error — network or protocol failure below the LM layer.
WriteError
¶
Bases: TransportError
Failed to write to an open socket.
WriteTimeout
¶
Bases: WriteError
Writing to the socket timed out.
Timeouts
dataclass
¶
How long to wait, in seconds, at each step of a request.
connect: TCP + TLS (and a proxy CONNECT) to the host.read: the next byte of the reply — headers first, then each body chunk. A model that is still thinking sends nothing, so this is the one to raise for slow local models and long non-streaming answers.write: sending the request bytes.pool: a free connection whenmax_connectionsare all busy.Nonewaits as long as it takes.
Every value must be positive (or None for pool); a zero or
negative timeout is a configuration mistake, not "no timeout".
TransportResponse
¶
Sync streaming response.
Iterating yields body chunks as bytes. Must be used as a context manager so the connection is properly returned to the pool (or closed) even on early exit.
iter_lines() -> Iterator[bytes]
¶
Yield newline-terminated byte lines from arbitrary body chunks.
AsyncTransportResponse
¶
Async streaming response. Async-iterate to get body chunks.
aiter_lines() -> AsyncIterator[bytes]
async
¶
Yield newline-terminated byte lines from arbitrary body chunks.
StdlibTransport
¶
Sync HTTP/1.1 transport using only the Python standard library.
Timeouts are per operation (_limits.py): read_timeout bounds the
wait for the NEXT byte, so a streaming reply that keeps arriving never
trips it. pool_timeout bounds the wait for a free connection when
max_connections are busy; None waits indefinitely.
copy() -> 'StdlibTransport'
¶
A fresh, open transport with this one's configuration and none of its connections (an interactive runner closed the original).
stream(request: TransportRequest) -> TransportResponse
¶
Open a stream to the URL, returning a TransportResponse whose iteration yields body bytes.
The response MUST be used as a context manager (or have .close()
called) — otherwise the underlying connection leaks.
StdlibAsyncTransport
¶
Async HTTP/1.1 transport on asyncio streams. Same knobs and per-
operation timeout semantics as :class:StdlibTransport. Its pool
belongs to the event loop that first used it; one transport per loop.
FetchTransport
¶
The :class:AsyncTransport over the host's fetch.
fetch may be given (a test double, a wrapped fetch); by default
it is the host's global. read_timeout bounds the initial fetch
(through response headers) and each body chunk, not the whole response.
A request's explicit read_timeout overrides it. The host decodes
compression; visible Content-Encoding is checked against INV-053, never
inflated again. CORS-hidden headers cannot be checked.