Sentence Stream
A small sentence splitter for text streams.
Sentences come out as soon as their boundary is certain, so a stream of text chunks — from an LLM, say — can be handed to a text-to-speech engine a sentence at a time instead of waiting for the whole response.
Install
pip install sentence-stream
Example
from sentence_stream import stream_to_sentences
text_chunks = [
"Text chunks that a",
"re not on",
" word or se",
"ntence boundarie",
"s. But, they w",
"ill sti",
"ll get sp",
"lit right",
"!!! Goo",
"d",
]
assert list(stream_to_sentences(text_chunks)) == [
"Text chunks that are not on word or sentence boundaries.",
"But, they will still get split right!!!",
"Good",
]
Where the chunk boundaries fall never changes the result: the same text split
into different chunks always produces the same sentences. A single complete
string works too — stream_to_sentences("First sentence. Second sentence.") —
for when there is nothing to stream.
For async streams, use async_stream_to_sentences:
from sentence_stream import async_stream_to_sentences
async def main(text_stream):
async for sentence in async_stream_to_sentences(text_stream):
print(sentence)
Pushing chunks yourself
SentenceBoundaryDetector is the same logic without the iterator, for when text
arrives by callback rather than from something you can loop over. add_chunk
returns the sentences that are now complete, and finish returns whatever text
is left over — an empty string if there is none.
from sentence_stream import SentenceBoundaryDetector
detector = SentenceBoundaryDetector()
for sentence in detector.add_chunk("Hello world. Goodbye"):
print(sentence) # Hello world.
if final_sentence := detector.finish():
print(final_sentence) # Goodbye
A detector resets itself in finish, so it can be reused for the next stream.
What counts as a boundary
- Terminators followed by whitespace and a capital letter:
.!?… - CJK terminators, which need no whitespace after them:
。!?。, along with trailing closers such as」』)》 - Terminators for other scripts:
؟(Arabic),۔(Urdu),।॥(Devanagari),។៕(Khmer),။(Myanmar),།༎(Tibetan),።(Ethiopic),։(Armenian), and;in Greek - A blank line
A sentence may open with punctuation before its first letter — ¿ ¡ « „
and quotation marks — and may end with closing quotes or brackets.
Abbreviations are held rather than split on: initials (Jonas E. Smith), dotted
acronyms (U.S.), and a list of known words (Mr., Mt., etc.).
Markdown emphasis is stripped from the output, so **Bold** is read as Bold.
Text that only resembles markup is left alone, including 2*3*4.
Known limitations
This is a heuristic splitter, not a parser. It errs toward leaving a sentence whole, since an over-eager split is more noticeable when read aloud than a long sentence.
- Thai and Lao are never split. Neither script has a sentence terminator — sentences are separated with a space — so there is nothing to key on.
- Georgian is never split. The Mkhedruli script has no uppercase, and a boundary needs a capital letter after the terminator.
- List markers are split off as their own sentence:
1. The first itembecomes1.andThe first item, unless the item is emphasized. - A sentence-ending abbreviation stays joined to the sentence after it:
I live in the U.S. How about you?comes out whole, because the sameU.S.also appears mid-sentence inthe U.S. Government. - Spaced ellipses (
. . .) are treated as a boundary.
The tests/english_golden_rules.py suite records which of pySBD's golden rules
pass and pins the output for those that do not.
Metadata
Release files for sentence-stream 1.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sentence_stream-1.4.0.tar.gz | 24.6 kB | With provenance | Details for sentence_stream-1.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sentence_stream-1.4.0-py3-none-any.whl | Python 3 | none | any | Details for sentence_stream-1.4.0-py3-none-any.whl |
Total release size: 39.0 kB
Release files / sentence_stream-1.4.0.tar.gz
| Download URL | sentence_stream-1.4.0.tar.gz |
|---|---|
| Size | 24.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b7c3b9c8d96090d84f07d719317e29298ad897fca666455a12160e0780890e54
|
|
BLAKE2b-256 checksum How to use checksums |
728be4b4cf9df7b9f3ceb1d0fe066243e32fb74990f2d71c668465b5e27e0001
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.
Transparency logRelease files / sentence_stream-1.4.0-py3-none-any.whl
| Download URL | sentence_stream-1.4.0-py3-none-any.whl |
|---|---|
| Size | 14.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
489f008cbcaa12858088f7f83033c07a85d57b3c6a8ee7838bbfd17dd7058b4e
|
|
BLAKE2b-256 checksum How to use checksums |
8b1f46f243a1d9dfd3c4021a7d38de894babd8c96572dc035d1872a258427a8f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.
Transparency logSecurity for sentence-stream 1.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for sentence_stream-1.4.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 28, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.