Skip to main content

morpheme (Python)

Minimal Python bindings for the morpheme tokenizer library, built with PyO3 and maturin. The API is deliberately small: load a tokenizer, encode, decode, count tokens, and look up the vocabulary. It does not reproduce the Hugging Face tokenizers Python API.

Usage

import morpheme

tok = morpheme.Tokenizer.from_file("tokenizer.json")
# or: morpheme.Tokenizer.from_pretrained("bert-base-uncased")

enc = tok.encode("Hello world!")
print(enc.ids, enc.tokens, enc.offsets)  # offsets are character spans
print(tok.count("Hello world!"))          # == len(enc.ids)
print(tok.decode(enc.ids))                # "hello world!"
batch = tok.encode_batch(["a", "b"])      # releases the GIL
try:
    morpheme.Tokenizer.from_file("missing.json")
except morpheme.MorphemeError as e:
    print(e)

Building locally

cd bindings/python
uv run --with maturin --with pytest sh -c 'maturin develop && pytest'

The Rust crate is publish = false (it is not on crates.io); wheels are built with maturin build --release.

Prebuilt wheels cover Linux (x86_64, aarch64), macOS (Apple silicon) and Windows (x64); other platforms, including Intel macOS, install from the sdist and need a Rust toolchain.

Metadata

Release files for morpheme 0.4.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 morpheme 0.4.0
File Size Uploaded
morpheme-0.4.0.tar.gz 173.6 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for morpheme 0.4.0
File
morpheme-0.4.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details
morpheme-0.4.0-cp39-abi3-manylinux_2_28_aarch64.whl CPython 3.9 abi3 Linux glibc 2.28+ ARM64 Details
morpheme-0.4.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details
morpheme-0.4.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details

Total release size: 11.1 MB

Release files / morpheme-0.4.0.tar.gz

Download URL morpheme-0.4.0.tar.gz
Size 173.6 kB
Tags Source
SHA-256 checksum
How to use checksums
e6205e77626687dd9a611cc74f738f1c93bdc53b0aeb9f6697e82ffe873a0e50
BLAKE2b-256 checksum
How to use checksums
bbe037327fe8124ecad8401794e6ac7090947c7e12230de3a8282d930c75e7ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / morpheme-0.4.0-cp39-abi3-win_amd64.whl

Download URL morpheme-0.4.0-cp39-abi3-win_amd64.whl
Size 2.6 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
3d9cd404fd821172cd56eafc08ced058e7ebe91dc2d9163b7bcec14af88255fe
BLAKE2b-256 checksum
How to use checksums
4712788a979b7f41708317bb888eb5467da69c75bfe6b35abbf8fc56d81f73b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / morpheme-0.4.0-cp39-abi3-manylinux_2_28_aarch64.whl

Download URL morpheme-0.4.0-cp39-abi3-manylinux_2_28_aarch64.whl
Size 2.8 MB
Tags CPython 3.9 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
ee2490f464c9611610e7a9da145fbd8253ff6420465189cf19c75e541197b78f
BLAKE2b-256 checksum
How to use checksums
f4a4bbdcf54b5beb260fc45c7b7162a803e8b68292e223d8b0474c0d0ae1b05c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / morpheme-0.4.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL morpheme-0.4.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.9 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
361c68a598374d6474bf01a599009812e56c1e9458210648a7fb9030507f42fe
BLAKE2b-256 checksum
How to use checksums
3cf354057ad97bbff8b56b1ab2c078bf3a115bd0c19e391a37328edbab46c75b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release files / morpheme-0.4.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL morpheme-0.4.0-cp39-abi3-macosx_11_0_arm64.whl
Size 2.6 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
7c090368c0d563f6558f700cbf68ce05e0952e15503694c60c85a2e99c2a1666
BLAKE2b-256 checksum
How to use checksums
1d9ca8f7507c722b3af3ac7b533411f4ac73b41c5a530e46e6f5e27c4c4ef743
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Release history Release notifications | RSS feed

0.5.0

5 release files

This release

0.4.0 This release

5 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