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.
Metadata
Release files for bpe-openai 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| bpe_openai-0.1.4.tar.gz | 7.5 MB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| bpe_openai-0.1.4-cp39-abi3-win_amd64.whl | CPython 3.9 | abi3 | Windows x86-64 | Details |
| bpe_openai-0.1.4-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| bpe_openai-0.1.4-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ ARM64 | Details |
| bpe_openai-0.1.4-cp39-abi3-macosx_11_0_arm64.whl | CPython 3.9 | abi3 | macOS 11.0+ ARM64 | Details |
Total release size: 173.9 MB
Release files / bpe_openai-0.1.4.tar.gz
| Download URL | bpe_openai-0.1.4.tar.gz |
|---|---|
| Size | 7.5 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
834b55afffb33033c51d09283cf65c988daa1ff83be40c58ce8c7fa7ec6f5dd9
|
|
BLAKE2b-256 checksum How to use checksums |
39d0b40f8f84cf13d97e8c748ea526360fe5da6392825dd9b037599557ca31ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Oct 17, 2025.
Transparency logRelease files / bpe_openai-0.1.4-cp39-abi3-win_amd64.whl
| Download URL | bpe_openai-0.1.4-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 41.4 MB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
b382c54f267922144ff0e851a0dc4f19fb6734bcb15d2963229c09c7386977cb
|
|
BLAKE2b-256 checksum How to use checksums |
b8f927f9b0b61664aa7fff929dcaa1f95949e66fab48aad14352f9459f7a05d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Oct 17, 2025.
Transparency logRelease files / bpe_openai-0.1.4-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | bpe_openai-0.1.4-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 41.6 MB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
91dde48b7c27a155ec94563ef488d95267bd17e2e8db360aba299ca9819335ba
|
|
BLAKE2b-256 checksum How to use checksums |
0078ff91a635cb338a141ed36f22a206d20a6fb8fd623bb52a17921303c3dce0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Oct 17, 2025.
Transparency logRelease files / bpe_openai-0.1.4-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | bpe_openai-0.1.4-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 41.5 MB |
| Tags | CPython 3.9 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
08fee77717d56bd6ffa86b46283f8ce5553151cc0e4967001af26f37b81c3276
|
|
BLAKE2b-256 checksum How to use checksums |
f15962c084d1ca0e9825e19dcd65c127224b097b692d1e582322e805faa85584
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Oct 17, 2025.
Transparency logRelease files / bpe_openai-0.1.4-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | bpe_openai-0.1.4-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 42.0 MB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
a754c738d85dca11bfd1d7ce474419bf39a3e2bdb79b7a0c40329c97f350cfa5
|
|
BLAKE2b-256 checksum How to use checksums |
74f676b27244fae799b7716941fce2f5d5062ad2b392ed7371aeb18dddc99603
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Oct 17, 2025.
Transparency log