Streaming API
stream() and convert_iter() accept a document in string chunks. The current
Python implementation buffers the complete input and converts it at
finalization. It provides batch-equivalent results, not bounded-memory or
early-output streaming.
For any division of a document into chunks, the combined stream output equals
one convert() call on the combined input. A boundary inside a word, HTML tag
or Markdown construct does not change conversion. This guarantee applies to
both stream() and convert_iter().
Push and finish
Every successful push() returns an empty string. finish() joins the input
and converts it once, even when the input is empty. The format accepts the
same InputFormat or MarkdownOptions value as convert().
A stream keeps a reference to its converter, so the converter stays alive
while the stream does. Give each document its own stream and each stream one
consumer. Successful finish(), a failed push(), or a failed finish()
makes the stream terminal; every later push or finish raises
RuntimeError. To retry after an error, create a new stream.
Convert an iterable
convert_iter() adapts an iterable of string chunks to an iterator of
nonempty output chunks:
Format validation happens when convert_iter() is called. Input is consumed
when the returned iterator advances. The current implementation yields one
result after normal input exhaustion, or none for empty output. If the input
iterator raises or the output iterator is closed early, no partial document
is converted.
Parallel documents
Reuse one configured converter for independent documents. Native conversion releases the GIL and keeps parser, homophone and first-occurrence state local to each call:
This does not make a mutable stream safe for several consumers. Share the
converter and create separate streams instead. Python signals are checked
after native work returns, so a long conversion can delay
KeyboardInterrupt. There is no asyncio-specific interface.