Skip to main content

cppjieba-mmap

Linux native Chinese tokenizer for CPython 3.13 and later. Version 0.1.0 bundles a merged Taiwan dictionary and uses CppJieba Mix segmentation with HMM. The dictionary DAT uses a read-only shared memory mapping. Workers reuse its file-backed pages instead of allocating a private dictionary trie per process. HMM tables remain process-private.

Release wheels target manylinux_2_28 x86_64 and aarch64 for CPython 3.13, 3.14 and free-threaded 3.14. Wheels need no compiler at installation time. Source builds use setuptools, pybind11 3.0.1 and a C++17 compiler, without CMake. Runtime needs no OpenCC, jieba, network dictionary downloads or model server.

Install from source

Run these commands from this repository root:

uv venv --python 3.14
uv pip install '.[test]'
.venv/bin/python -m pytest
import cppjieba_mmap

tokenizer = cppjieba_mmap.Tokenizer(
    str(cppjieba_mmap.DICT_PATH),
    str(cppjieba_mmap.HMM_PATH),
    "/tmp/my-private-tokenizer-cache",
)
words = tokenizer.cut("超商取貨")

DICT_PATH and HMM_PATH are readable bundled pathlib.Path objects from import time. DICT_SHA256 identifies the exact uncompressed dictionary bytes. The dictionary is packaged uncompressed. No runtime conversion occurs. Its 582704 entries combine the pinned CppJieba dictionary with an OpenCC s2twp conversion of the supplied jieba-next dictionary. Duplicate surfaces retain the larger frequency. See PROVENANCE.md for exact inputs and hashes.

Output contract

cut(text: str) -> list[str] uses Jieba::Cut(text, words, true) (Mix + HMM), then removes whitespace-only tokens, matching the cpp-tw retrieval evaluation. Other token text and ordering stay unchanged. English case is preserved. Empty and whitespace-only inputs return []. In particular, 256GB remains 256 / GB; the wrapper does not silently alter this evaluated behavior.

Cache and concurrency

Cache names contain dictionary SHA-256, the native cache format revision, architecture and endianness. Changed dictionary bytes cannot select the same DAT. HMM data is loaded separately and does not determine the DAT identity.

Every constructor locks a per-key flock file. Exactly one simultaneous constructor builds a missing DAT. A private temporary directory holds the dictionary snapshot and incomplete DAT. Publication uses an atomic rename within the cache filesystem after validation, fsync and chmod 0444. Readers attach using PROT_READ | MAP_SHARED. Locks remain on disk for reuse. Truncated or header-mismatched cache files are rebuilt under the same lock. Existing instances retain their mapped inode while a replacement is published.

Use a trusted local filesystem and one OS user for all workers. Cache directories must not be writable by other users. Input models must be trusted and remain unchanged while constructing a tokenizer. Dictionary bytes are snapshotted even on cache hits, avoiding hash/read races. Temporary snapshots are deleted after construction. A killed process can leave a private .build-* directory; it is never treated as a published cache. Remove such directories only while no constructors run. The package does not evict older DAT files.

Threads and free threading

The binding releases the GIL during native construction and cutting. One instance supports concurrent cut calls: the engine exposes no mutators, dictionary/model lookups are const, and cut/DAG/Viterbi buffers are call-local. The native module declares py::mod_gil_not_used(). The process-global upstream umask mutation is removed. Constructors use separate engine instances and per-cache file locks. Python result filtering runs after the native call returns.

This is not a claim of subinterpreter support or lock-free Python execution. Tests exercise two threads with a released GIL and three spawned processes. HMM tables and per-call buffers remain process-private; only the DAT is shared.

Limits

The DAT header is validated, but this is not a sandbox for malicious native cache contents or untrusted model files. Do not reuse caches written by other users. Inputs consume memory proportional to their length. No Windows support, user-dictionary mutation, POS tagging API, query/full mode or cache eviction is exposed. See PROVENANCE.md for source pins, patches and third-party licenses.

Releases

CI builds and tests one CPython 3.14 x86_64 wheel on pushes and pull requests. The release workflow tests all six Python/architecture wheels on native Linux runners, builds an sdist, and publishes only after every build succeeds.

Before the first release, configure a PyPI Trusted Publisher for project cppjieba-mmap, owner coseto6125, repository cppjieba-mmap, workflow release.yml, and environment pypi. Configure that GitHub environment with release approval protection. No PyPI API token is required.

Set the package version in pyproject.toml, then push the matching v<version> tag. For this version the tag is v0.1.0. The workflow rejects a version mismatch. Only the isolated publish job receives id-token: write.

License

Package glue is MIT-licensed under LICENSE. Bundled source, dictionary and conversion resources retain their own notices in licenses/ and PROVENANCE.md. The distribution's combined license expression includes these third-party licenses; it does not relicense them as MIT.

Metadata

Release files for cppjieba-mmap 0.1.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 cppjieba-mmap 0.1.0
File Size Uploaded
cppjieba_mmap-0.1.0.tar.gz 3.3 MB Details

Built distributions (wheels)

Table of built distributions (wheels) for cppjieba-mmap 0.1.0
File
cppjieba_mmap-0.1.0-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
cppjieba_mmap-0.1.0-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl CPython 3.14 CPython 3.14 free-threading Linux glibc 2.26+ ARM64, Linux glibc 2.28+ ARM64 Details
cppjieba_mmap-0.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 Details
cppjieba_mmap-0.1.0-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl CPython 3.14 CPython 3.14 Linux glibc 2.26+ ARM64, Linux glibc 2.28+ ARM64 Details
cppjieba_mmap-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64, Linux glibc 2.27+ x86-64 Details
cppjieba_mmap-0.1.0-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl CPython 3.13 CPython 3.13 Linux glibc 2.26+ ARM64, Linux glibc 2.28+ ARM64 Details

Total release size: 24.1 MB

Release files / cppjieba_mmap-0.1.0.tar.gz

Download URL cppjieba_mmap-0.1.0.tar.gz
Size 3.3 MB
Tags Source
SHA-256 checksum
How to use checksums
dc8a1b4f85e75254923816ac76689affd4cf1e81971c11d631da389793040898
BLAKE2b-256 checksum
How to use checksums
433c15581dfcaac5c9f8216577dd61f1a40652704cdadd641106403d234d0070
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 21, 2026.

Transparency log

Release files / cppjieba_mmap-0.1.0-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL cppjieba_mmap-0.1.0-cp314-cp314t-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 3.5 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
669a37b806be977bc0c1e40373ac072e23f38c522801abb76c92bb749d7ccdad
BLAKE2b-256 checksum
How to use checksums
48eca4dadf9b864fe5ba8c6f5dba2ca63a14ecc8f8d674db439288eda3c8034a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 21, 2026.

Transparency log

Release files / cppjieba_mmap-0.1.0-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl

Download URL cppjieba_mmap-0.1.0-cp314-cp314t-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Size 3.5 MB
Tags CPython 3.14 CPython 3.14 free-threading Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
0a30af8f090c04c13dcf52e790aa0d016ef9a0dd93d1a0db5395ee65298fcc61
BLAKE2b-256 checksum
How to use checksums
15ce0815596fe5afdd9414c98da0dd7fa2ea84b947ea3ef2e5ac495803883426
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 21, 2026.

Transparency log

Release files / cppjieba_mmap-0.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL cppjieba_mmap-0.1.0-cp314-cp314-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 3.5 MB
Tags CPython 3.14 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
2c6512cae184c28cbf5338b6f181de2e3c8ea694f09fb7c1bb9a29606cfaee43
BLAKE2b-256 checksum
How to use checksums
06757bed07330f30ad39321057092c5e3648dd58fcbe61fdd4e6b87d61a549e0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 21, 2026.

Transparency log

Release files / cppjieba_mmap-0.1.0-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl

Download URL cppjieba_mmap-0.1.0-cp314-cp314-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Size 3.5 MB
Tags CPython 3.14 Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
f98596782921c9b7a7fe91246d575c24468466232e6f289f1f3678df6486226e
BLAKE2b-256 checksum
How to use checksums
7218024a9c8137f7141140b91632001e7089bd6dcff2dcddcfaebf81ece0107b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 21, 2026.

Transparency log

Release files / cppjieba_mmap-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl

Download URL cppjieba_mmap-0.1.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Size 3.5 MB
Tags CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
bcbc2b71a2e4ead1f12fb4399345e7abcc8f8d9cf4897057325f9b7b2a65aa18
BLAKE2b-256 checksum
How to use checksums
7988422248e18499feee32df964b6c2a57c450a916df9d8f08534ceced757399
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 21, 2026.

Transparency log

Release files / cppjieba_mmap-0.1.0-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl

Download URL cppjieba_mmap-0.1.0-cp313-cp313-manylinux_2_26_aarch64.manylinux_2_28_aarch64.whl
Size 3.5 MB
Tags CPython 3.13 Linux glibc 2.26+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
7da7a125b4440a0e0724afc1439c0939c170fbd52b0182e0a44425b1c64eb34e
BLAKE2b-256 checksum
How to use checksums
c41271758361634879d65f77dcff25149acd001de80f15487753620e6230d476
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 21, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

7 release files

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