Skip to content

dorm.contrib.streaming

Bytes-yielding streaming serialisers (JSON / JSONL / CSV). Memory-bounded; framework-agnostic — use with FastAPI's StreamingResponse, Starlette, aiohttp, etc.

API

dorm.contrib.streaming.stream_json(source: Any, *, chunk_size: int = 1000) -> Iterator[bytes]

Yield bytes of a single [{...}, {...}] JSON array.

Suitable for clients that expect a JSON document; the encoded bytes are streamed comma-separated so memory stays flat.

dorm.contrib.streaming.stream_jsonl(source: Any, *, chunk_size: int = 1000) -> Iterator[bytes]

Yield newline-delimited JSON. One full record per line.

dorm.contrib.streaming.stream_csv(source: Any, *, chunk_size: int = 1000, columns: list[str] | None = None) -> Iterator[bytes]

Yield RFC-4180 CSV bytes. The header row is built from columns when provided, otherwise from the first row's keys.

Subsequent rows that lack a column emit an empty cell; extra keys are dropped (CSV's grid shape is non-negotiable).

dorm.contrib.streaming.stream_ndjson_pretty(source: Any, *, chunk_size: int = 1000) -> Iterator[bytes]

Yield indented JSON records, one record per multi-line block.

Use for less-grade human inspection only — the format is not a valid JSONL document for downstream parsers.

dorm.contrib.streaming.astream_json(source: Any, *, chunk_size: int = 1000) -> AsyncIterator[bytes] async

dorm.contrib.streaming.astream_jsonl(source: Any, *, chunk_size: int = 1000) -> AsyncIterator[bytes] async

dorm.contrib.streaming.astream_csv(source: Any, *, chunk_size: int = 1000, columns: list[str] | None = None) -> AsyncIterator[bytes] async

Async CSV stream. See :func:stream_csv for the contract.