Python bindings wrapping the bpe-openai Rust tokenizer crate with a tiktoken-compatible API.
Project description
bpe-openai
bpe-openai is a tiktoken-compatible tokenizer API backed by the Rust
bpe-openai crate. Pathlit maintains the Python wrapper, while the core
tokenizer implementation is developed by GitHub and published in the
rust-gems
project. Published wheels bundle the tokenizer data, so the package works
out of the box on Python 3.9 and newer.
Installation
pip install bpe-openai
Installing from a source distribution requires a Rust toolchain:
pip install --no-binary bpe-openai bpe-openai==<version>
Quick start
import bpe_openai as bpe
enc = bpe.get_encoding("cl100k_base")
tokens = enc.encode("Smoke tests keep releases honest.")
print(tokens)
print(enc.decode(tokens))
# Model-aware helper
chat_enc = bpe.encoding_for_model("gpt-4o")
Compatibility snapshot
| API / Feature | Status | Notes |
|---|---|---|
get_encoding, encoding_for_model |
✅ | Supports cl100k_base, o200k_base, voyage3_base, and related models |
Encoding.encode, Encoding.decode |
✅ | Rust backend ensures parity with tiktoken |
Encoding.encode_batch |
✅ | Matches tiktoken's batching behaviour |
| Custom special tokens | ⚠️ | Not yet configurable at runtime |
| Legacy GPT-2 / r50k / p50k encodings | ⚠️ | Planned; current focus is on modern OpenAI models |
Metrics hook (set_metrics_hook) |
✅ | Emits model, token count, latency, backend version |
Legend: ✅ fully supported · ⚠️ partial / planned
Why we built it
Long, repetitive prompts can hit pathological slow paths in tiktoken. To
stress-test both libraries we encoded inputs of the form "A" * n and measured
latency. bpe-openai stays effectively flat while tiktoken grows sharply with
input length, unlocking workloads like prompt templating and log chunking that
stalled with the reference implementation.
Smoke test
After installing from PyPI, run a quick confidence check:
python - <<'PY'
import bpe_openai as bpe
enc = bpe.get_encoding("cl100k_base")
text = "Smoke tests keep releases honest."
tokens = enc.encode(text)
assert enc.decode(tokens) == text
print("✅ bpe-openai smoke test passed.")
PY
Repository layout
python/– Python package wrapping the Rust tokenizer as a CPython extension.rust/– Rust crate that loads tokenizer specs and exposes the fast BPE APIs.scripts/– Helper utilities for benchmarking, parity checks, and data sync.vendor/– Vendored tokenizer definitions sourced from GitHub's upstream release.
Development
python -m venv .venv
source .venv/bin/activate
python scripts/sync_tokenizer_data.py # ensures tokenizer assets are copied
pip install maturin
cd python
maturin develop --release
pytest
The repository includes scripts/sync_tokenizer_data.py to copy the vendored
.tiktoken.gz files into python/bpe_openai/data/ before building wheels or an
sdist.
Release process (maintainers)
- Update the version string in
python/pyproject.toml. The runtime fallback reads the same file, so one change keeps packaging metadata andbpe_openai.__version__in sync. - Run
python scripts/sync_tokenizer_data.pyto refresh bundled assets. - Commit the changes and tag the release (
git tag vX.Y.Z). - Push the tag. The
Release WheelsGitHub Actions workflow builds wheels, publishes a GitHub release, and uploads to PyPI via Trusted Publishing.
Contributing
Contributions are warmly welcomed—whether you are filing a bug, improving parity with new OpenAI models, or squeezing out more performance. Open an issue or pull request and the Pathlit team will review quickly.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bpe_openai-0.1.2.tar.gz.
File metadata
- Download URL: bpe_openai-0.1.2.tar.gz
- Upload date:
- Size: 7.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc9b268b96fa347e04caebd652adcdd910f0fe8ced01a7f7468a25049a3f88c9
|
|
| MD5 |
4811da8a91e28f7b334b5cf39f4aa8b3
|
|
| BLAKE2b-256 |
d43d08e00eb2fd846a764a2402ccc60c6b8edcda2bd59ac397d8d4e4a4eff1da
|
Provenance
The following attestation bundles were made for bpe_openai-0.1.2.tar.gz:
Publisher:
release-wheels.yml on Pathlit-Inc/bpe-openai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bpe_openai-0.1.2.tar.gz -
Subject digest:
bc9b268b96fa347e04caebd652adcdd910f0fe8ced01a7f7468a25049a3f88c9 - Sigstore transparency entry: 596460617
- Sigstore integration time:
-
Permalink:
Pathlit-Inc/bpe-openai@3f7a8b44c3798026e423785e8a097717530eada9 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/Pathlit-Inc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-wheels.yml@3f7a8b44c3798026e423785e8a097717530eada9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file bpe_openai-0.1.2-cp39-abi3-win_amd64.whl.
File metadata
- Download URL: bpe_openai-0.1.2-cp39-abi3-win_amd64.whl
- Upload date:
- Size: 41.4 MB
- Tags: CPython 3.9+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7e05356b53146834e2107642ed688f6dee361db8cb5d6ee2cd7ab28bd00e7d8
|
|
| MD5 |
9cf448ec9054cfb1b5cedbf0915841d7
|
|
| BLAKE2b-256 |
0c76386bca40c79042ddf5494753507c359367ac070efeb3c73e347a6386ca98
|
Provenance
The following attestation bundles were made for bpe_openai-0.1.2-cp39-abi3-win_amd64.whl:
Publisher:
release-wheels.yml on Pathlit-Inc/bpe-openai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bpe_openai-0.1.2-cp39-abi3-win_amd64.whl -
Subject digest:
e7e05356b53146834e2107642ed688f6dee361db8cb5d6ee2cd7ab28bd00e7d8 - Sigstore transparency entry: 596460620
- Sigstore integration time:
-
Permalink:
Pathlit-Inc/bpe-openai@3f7a8b44c3798026e423785e8a097717530eada9 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/Pathlit-Inc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-wheels.yml@3f7a8b44c3798026e423785e8a097717530eada9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file bpe_openai-0.1.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: bpe_openai-0.1.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 41.6 MB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e0d69c08e8be176d479230491cdb095131e90b463f02ad87f01b1f92fd040f98
|
|
| MD5 |
0d238327e3503fe0eac2797b8a4e1465
|
|
| BLAKE2b-256 |
284809c25363b6df76cf23e87c4a77fb03bbc39a103002dc5adb8169930ce6c6
|
Provenance
The following attestation bundles were made for bpe_openai-0.1.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
release-wheels.yml on Pathlit-Inc/bpe-openai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bpe_openai-0.1.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
e0d69c08e8be176d479230491cdb095131e90b463f02ad87f01b1f92fd040f98 - Sigstore transparency entry: 596460623
- Sigstore integration time:
-
Permalink:
Pathlit-Inc/bpe-openai@3f7a8b44c3798026e423785e8a097717530eada9 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/Pathlit-Inc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-wheels.yml@3f7a8b44c3798026e423785e8a097717530eada9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file bpe_openai-0.1.2-cp39-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: bpe_openai-0.1.2-cp39-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 42.0 MB
- Tags: CPython 3.9+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60a99f94f6d5dcbf323c77df9572fa53c7d95242be7f87f1544e6dcbbaefb688
|
|
| MD5 |
d705fbd140043827d34982f77064b378
|
|
| BLAKE2b-256 |
275b366708ff0145e6b7199715784a5c26b2c420f76a48c9384ce6ca9bb7f0f7
|
Provenance
The following attestation bundles were made for bpe_openai-0.1.2-cp39-abi3-macosx_11_0_arm64.whl:
Publisher:
release-wheels.yml on Pathlit-Inc/bpe-openai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bpe_openai-0.1.2-cp39-abi3-macosx_11_0_arm64.whl -
Subject digest:
60a99f94f6d5dcbf323c77df9572fa53c7d95242be7f87f1544e6dcbbaefb688 - Sigstore transparency entry: 596460619
- Sigstore integration time:
-
Permalink:
Pathlit-Inc/bpe-openai@3f7a8b44c3798026e423785e8a097717530eada9 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/Pathlit-Inc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-wheels.yml@3f7a8b44c3798026e423785e8a097717530eada9 -
Trigger Event:
push
-
Statement type: