Skip to main content

⚡ fast-bunkai

Publish PyPI

⚡ FastBunkai is a Python library that splits long Japanese and English texts into natural sentences, providing a highly compatible API with megagonlabs/bunkai while its Rust core delivers roughly 40–285× faster segmentation than the original Python implementation.

⚡ fast-bunkai は、日本語・英語の長い文章を自然な文単位に切り出すための Python ライブラリです。純粋 Python 実装である megagonlabs/bunkai と高い互換性がある API を提供しつつ、内部を Rust で最適化することで、オリジナルの Python 版と比べ約40〜285倍の高速化を実現しています。


目次|Table of Contents

✨ Highlights

  • 🔁 Drop-in replacement: mirrors the FastBunkai / Bunkai APIs and annotations, including Janome-based morphological spans.
  • 🦀 Rust-powered core: heavy annotators (facemark, emoji, dot exceptions, indirect quotes, etc.) run inside a PyO3 module that releases the Python GIL.
  • ⚡ Serious speed: real-world workloads observe 40×–285× faster segmentation than pure Python bunkai (details below).
  • 🧵 Thread-safe by design: no global mutable state; calling FastBunkai concurrently from threads or asyncio tasks is supported.
  • 🛫 CLI parity: ships a fast-bunkai executable compatible with bunkai’s pipe-friendly interface and --ma morphological mode.

🚀 Quick Start

Install

uv pip install fast-bunkai

Python Usage

from fast_bunkai import FastBunkai

splitter = FastBunkai()
text = "羽田から✈️出発して、友だちと🍣食べました。最高!また行きたいな😂でも、予算は大丈夫かな…?"
for sentence in splitter(text):
    print(sentence)

Output:

羽田から✈️出発して、友だちと🍣食べました。
最高!
また行きたいな😂
でも、予算は大丈夫かな…?

🧰 CLI Examples

fast-bunkai provides the same pipe-friendly command-line interface as bunkai.

echo -e '宿を予約しました♪!▁まだ2ヶ月も先だけど。▁早すぎかな(笑)楽しみです★\n2文書目です。▁改行を含みます。' \
  | uvx fast-bunkai

Output (sentence boundaries marked with │, newlines preserved via ▁):

宿を予約しました♪!▁│まだ2ヶ月も先だけど。▁│早すぎかな(笑)│楽しみです★
2文書目です。▁│改行を含みます。

Morphological output is also available:

echo -e '形態素解析し▁ます。結果を 表示します!' | uvx fast-bunkai --ma
形態素	名詞,一般,*,*,*,*,形態素,ケイタイソ,ケイタイソ
解析	名詞,サ変接続,*,*,*,*,解析,カイセキ,カイセキ
し	動詞,自立,*,*,サ変・スル,連用形,する,シ,シ
▁
EOS
ます	助動詞,*,*,*,特殊・マス,基本形,ます,マス,マス
。	記号,句点,*,*,*,*,。,。,。
EOS
結果	名詞,副詞可能,*,*,*,*,結果,ケッカ,ケッカ
を	助詞,格助詞,一般,*,*,*,を,ヲ,ヲ
	記号,空白,*,*,*,*, ,*,*
表示	名詞,サ変接続,*,*,*,*,表示,ヒョウジ,ヒョージ
し	動詞,自立,*,*,サ変・スル,連用形,する,シ,シ
ます	助動詞,*,*,*,特殊・マス,基本形,ます,マス,マス
!	記号,一般,*,*,*,*,!,!,!
EOS

📊 Benchmarks

Reproduce the bundled benchmark suite (correctness check + timing vs. bunkai):

uv run python scripts/benchmark.py --repeats 3 --jp-loops 100 --en-loops 100 --custom-loops 10

Latest local run (2025-10-11) reported:

Corpus Docs bunkai (mean) fast-bunkai (mean) Speedup
Japanese 200 253.92 ms 5.55 ms 45.72×
English 200 209.77 ms 4.94 ms 42.48×
Long text* 20 1330.95 ms 4.67 ms 285.10×

*Long text corpus contains mixed Japanese/English paragraphs with emojis and edge cases; the Rust pipeline processes characters in a single pass, whereas pure Python bunkai stacks regex scans, so the gap widens dramatically on longer documents.

Actual numbers vary by hardware, but the Rust core consistently outperforms pure Python bunkai by an order of magnitude or more.

🧠 Architecture Snapshot

  • 🦀 Rust core (src/lib.rs): facemark & emoji annotators, dot/number exceptions, indirect quote handling, and more. Uses PyO3 abi3 bindings and releases the GIL with py.allow_threads.
  • 😀 Emoji metadata (src/emoji_data.rs): generated via scripts/generate_emoji_data.py, mapping Unicode codepoints to bunkai-compatible categories.
  • 🐍 Python layer (fast_bunkai/): wraps the Rust segment function, mirrors bunkai annotations with dataclasses, and builds Janome spans through MorphAnnotatorJanome for drop-in parity.

🛠️ Development Workflow

uv sync --reinstall
uv run python scripts/generate_emoji_data.py  # regenerate emoji table when emoji libs change
uv run tox -e pytests,lint,typecheck,rust-fmt,rust-clippy

For manual Rust checks:

cargo test face_mark_detection_matches_reference
cargo fmt --all
cargo clippy --all-targets -- -D warnings

🧪 Testing & Quality Gates

  • ✅ pytest (tests/test_compatibility.py): ensures Japanese・English texts, emoji-heavy samples, and parallel execution match bunkai outputs.
  • 🧹 Ruff: lint + format checks via tox -e lint,format-check.
  • 🧠 Pyright: type-checks the Python API surface.
  • 🧪 Rust unit tests: validate annotator logic remains in sync with reference behaviour.
  • 📈 Benchmarks: scripts/benchmark.py validates speed + correctness; normally executed in CI to avoid long local runs.

🙏 Acknowledgements

FastBunkai stands on the shoulders of the megagonlabs/bunkai project—ありがとうございます!

📄 License

Apache License 2.0

👤 Author

Yuichi Tateno (@hotchpotch)

Metadata

Release files for fast-bunkai 0.1.1

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

Built distributions (wheels)

Table of built distributions (wheels) for fast-bunkai 0.1.1
File Actions
fast_bunkai-0.1.1-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for fast_bunkai-0.1.1-cp310-abi3-win_amd64.whl
fast_bunkai-0.1.1-cp310-abi3-manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-64 Details for fast_bunkai-0.1.1-cp310-abi3-manylinux_2_28_x86_64.whl
fast_bunkai-0.1.1-cp310-abi3-manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.28+ ARM64 Details for fast_bunkai-0.1.1-cp310-abi3-manylinux_2_28_aarch64.whl
fast_bunkai-0.1.1-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl CPython 3.10 abi3 macOS 10.12+ x86-64, macOS 11.0+ ARM64, macOS 10.12+ universal2 (ARM64, x86-64) Details for fast_bunkai-0.1.1-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Total release size: 4.3 MB

Release files / fast_bunkai-0.1.1-cp310-abi3-win_amd64.whl

Download URL fast_bunkai-0.1.1-cp310-abi3-win_amd64.whl
Size 707.0 kB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
d33f859db83ff14e9c6a21b8acda516649f20d3d71be0788bdb06e4d9c574afc
BLAKE2b-256 checksum
How to use checksums
e9421d78cffeb4fa941388ef0a8a4df1b16c172164e1e0c0bda810e8c51f6594
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.2

Release files / fast_bunkai-0.1.1-cp310-abi3-manylinux_2_28_x86_64.whl

Download URL fast_bunkai-0.1.1-cp310-abi3-manylinux_2_28_x86_64.whl
Size 961.9 kB
Tags CPython 3.10 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
c35d36ab302484ec0c47b323acbb6814cd5bd2a9138c965d8b0ebbd55a70c57a
BLAKE2b-256 checksum
How to use checksums
614708234de4b17706af6def621515a3764ee235bbe0cc0efe7521230df51180
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.2

Release files / fast_bunkai-0.1.1-cp310-abi3-manylinux_2_28_aarch64.whl

Download URL fast_bunkai-0.1.1-cp310-abi3-manylinux_2_28_aarch64.whl
Size 933.7 kB
Tags CPython 3.10 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
1b700a41d64b9dfac702f4323d465677f1939ad6d424cc7fb3ba9c4a5aa06d5c
BLAKE2b-256 checksum
How to use checksums
2090b8741642ce6f6616af41c951f03535c49001028ffde50aeb6a3a5f7781ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.2

Release files / fast_bunkai-0.1.1-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl

Download URL fast_bunkai-0.1.1-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Size 1.7 MB
Tags CPython 3.10 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e0fa684fc542266808ccfac8742f1b95c59a864bd0f06a94b5cbfe8adb6955c2
BLAKE2b-256 checksum
How to use checksums
8867039584892f226e677544455981db3b540fa9948a3177997eb19fe7a553aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.2

Security for fast-bunkai 0.1.1

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

0.1.1 This release

4 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