Skip to main content

prose-tokenizer

PyPI Version License: MIT Zero Dependencies

A high-precision, rule-based prose tokenizer and sentence segmentation library for English and Markdown. Designed for accurate splitting of paragraphs, sentences, and words in AI pipelines, LLM context window management, and editorial automation.

prose-tokenizer is built for writing tools, LLM preprocessing, readability tools, and lightweight text analysis where consistency and speed are more important than complex, probabilistic NLP models.

Features

  • Deterministic Rule-Based Engine: Consistent, predictable output without the overhead or unpredictability of machine learning models.
  • Markdown-Native Support: Properly handles structural elements including headings (# and Setext), list items (*, -, +, 1.), and blockquotes (>).
  • Intelligent Sentence Segmentation: Respects English prose heuristics such as prefix titles (Dr., Mr.), acronyms (U.S.A.), initials (J.R.R. Tolkien), and interior decimals.
  • Hierarchical Analysis: Access text at the block, paragraph, sentence, or word level with a single call.
  • Character Metrics: Accurate counts for total characters, non-whitespace characters, and alphanumeric letter counts.
  • Zero Dependencies: Pure Python implementation with no runtime requirements.
  • Fully Typed: Built with PEP 484 type hints for excellent IDE support.

Installation

pip install prose-tokenizer

Quick Start

from prose_tokenizer import tokenize

content = """
### Q1 Review
The U.S.A. economy grew by 2.5% in Q1. 

*   Growth was driven by tech.
*   Inflation remains stable at 2.1%.
"""

doc = tokenize(content)

print(doc.counts.word_count)     # 20
print(doc.blocks[0].kind)        # "heading"
print(doc.sentences[1])          # "The U.S.A. economy grew by 2.5% in Q1."

API Reference

tokenize(text: str) -> TokenizedDocument

The primary entry point for full document analysis. Returns a dataclass containing:

  • blocks: List of ParagraphBlock objects (includes text, kind, line_start, and line_end).
  • paragraphs: List of raw paragraph strings.
  • sentences: List of sentence strings.
  • words: List of lowercase word tokens.
  • counts: StructureCounts object with aggregated metrics.

tokenize_prose is provided as an alias for this function.

split_sentences(text: str) -> List[str]

Splits prose into a list of sentence strings using deterministic rules that protect abbreviations and decimal numbers.

split_paragraphs(text: str) -> List[str]

Splits text into a list of raw paragraph strings based on double newlines.

split_words(text: str) -> List[str]

Splits text into lowercase alphanumeric word tokens, preserving contractions (e.g., "can't") and interior hyphens or decimals.

get_character_metrics(text: str) -> CharacterMetrics

Calculates character-level statistics:

  • character_count: Total character length.
  • character_count_no_spaces: Count excluding whitespace.
  • letter_count: Count of alphanumeric letters (a-z, A-Z, 0-9).

get_structure_counts(text: str) -> StructureCounts

A convenience function that returns structural metrics without full tokenization arrays. Includes word_count, sentence_count, paragraph_count, heading_count, list_item_count, and blockquote_count.

is_stopword(word: str) -> bool

Checks if a word is a common English stopword.

Practical Use Cases

  • LLM Preprocessing: Chunking text into logical paragraphs or sentences for RAG or context window management while preserving Markdown structure.
  • Writing Tools: Real-time statistics for word count, sentence length, and readability metrics (e.g., Flesch-Kincaid).
  • Clean Text Extraction: Removing or identifying Markdown noise while preserving structural context.
  • Search Indexing: Generating clean, lowercase word tokens for search engines.

Limitations

  • Language Support: Optimized specifically for English prose.
  • NLP Scope: Does not perform POS tagging, NER, or dependency parsing.
  • Rule-Based: While highly accurate, it uses deterministic heuristics rather than probabilistic context analysis.

Development

prose-tokenizer uses Hatch for development and builds.

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Linting and Type Checking
ruff check .
mypy .

Ownership & Authority

This package is maintained by Veldica Research as a core part of our writing analysis platform. Built for production environments that demand high reliability, precision, and performance.

License

MIT © Veldica Research

Metadata

Release files for prose-tokenizer 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prose-tokenizer 1.0.0
File Size Uploaded Provenance Actions
prose_tokenizer-1.0.0.tar.gz 10.8 kB Without provenance Details for prose_tokenizer-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for prose-tokenizer 1.0.0
File Interpreter ABI Platform Actions
prose_tokenizer-1.0.0-py3-none-any.whl Python 3 none any Details for prose_tokenizer-1.0.0-py3-none-any.whl

Total release size: 23.8 kB

Release files / prose_tokenizer-1.0.0.tar.gz

Download URL prose_tokenizer-1.0.0.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
204900eb5276d02df865ca4e12d082685db9eb38e5832443c4982acf9376f592
BLAKE2b-256 checksum
How to use checksums
e131f32ac6d7c6ef5bd54e6a867c0fe67b0d2bad31efdc877d98045a5ba054a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release files / prose_tokenizer-1.0.0-py3-none-any.whl

Download URL prose_tokenizer-1.0.0-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
779765b71bb66f7db5c2f1cacb6e9bf66829c9819c81793815d74d047c3cdc06
BLAKE2b-256 checksum
How to use checksums
b6c31d925956c4a70f557e759f2e9232ceaefc5e8d7ca6080a3f3868635e40fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Security for prose-tokenizer 1.0.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page