Baseten Tokenizer
High-performance, Rust-backed BPE tokenization for inference. The Python
package is named basetenkenizer.
Install
pip install basetenkenizer
Loading by Hugging Face model ID downloads tokenizer.json on first use and
then uses the local Hugging Face cache. Private or gated models use the usual
HF_TOKEN environment variable.
Encode text
from basetenkenizer import Tokenizer
tokenizer = Tokenizer.from_model("deepseek-ai/DeepSeek-V3.2")
encoding = tokenizer.encode(
"A very long prompt that is now much faster.",
add_special_tokens=False,
)
print(encoding.ids)
print(tokenizer.decode(encoding.ids))
Tokenizer.from_file("tokenizer.json") loads a local tokenizer. Encoding
objects expose ids, attention_mask, type_ids, and
special_tokens_mask; selected fields can be moved into NumPy arrays with
encoding.into_numpy(...).
Kimi K2.7 Code
Load the published tokenizer directly from its model repository:
from basetenkenizer import Tokenizer
tokenizer = Tokenizer.from_model("moonshotai/Kimi-K2.7-Code")
ids = tokenizer.encode("def hello():\n return 'world'").ids
For a chat prompt, preserve the boundary between template control tokens and
untrusted message content with encode_segments:
user_message = "Write a Python HTTP server."
segments = [
("<|im_user|>user<|im_middle|>", True),
(user_message, False),
("<|im_end|>", True),
("<|im_assistant|>assistant<|im_middle|><think>", True),
]
encoding = tokenizer.encode_segments(segments)
input_ids = encoding.ids
This is the minimal Kimi K2.7 Code user/assistant shape. Applications using system messages, tools, images, or existing assistant messages should render the complete official model template and retain the same control-text versus message-text boundaries.
Kimi K3
Kimi K3 uses XTML and a Python chat renderer rather than a Jinja chat template. Raw text can still be encoded normally:
from basetenkenizer import Tokenizer
tokenizer = Tokenizer.from_model("moonshotai/Kimi-K3")
ids = tokenizer.encode("Hello from Kimi K3").ids
For rendered chat, pass the official Kimi K3 renderer's EncodeSegment
objects to encode_segments as (segment.text, segment.allow_special). A
minimal user message followed by an assistant-generation prefix looks like
this:
user_message = "Explain speculative decoding."
segments = [
("<|open|>", True),
("message", False),
(" role", False),
('="', False),
("user", False),
('"', False),
("<|sep|>", True),
(user_message, False),
("<|close|>", True),
("message", False),
("<|sep|>", True),
("<|end_of_msg|>", True),
("<|open|>", True),
("message", False),
(" role", False),
('="', False),
("assistant", False),
('"', False),
("<|sep|>", True),
("<|open|>", True),
("response", False),
("<|sep|>", True),
]
encoding = tokenizer.encode_segments(segments)
input_ids = encoding.ids
Use Kimi K3's official build_chat_segments renderer for production
conversations involving tools, images, reasoning content, response schemas,
or multiple message types. Do not concatenate its segments before encoding:
doing so loses the special-token safety boundary.
Why encode_segments?
Each segment is a (text, allow_special) pair:
allow_special=Truerecognizes tokenizer control tokens emitted by a trusted chat renderer.allow_special=Falsetreats control-token-looking strings in user, tool, or attribute content as ordinary text.
tiktoken_safe=True is the default. It reproduces the chunk boundaries used
by legacy tiktoken tokenizers, including on very long inputs, so token IDs stay
compatible. Set it to False only when exact tiktoken parity is not required
and whole-segment BPE encoding is intentional.
Post-processing, truncation, and padding are applied after all segment IDs have been joined.
Use with Transformers
Call patch_transformers before loading a tokenizer:
import basetenkenizer
basetenkenizer.patch_transformers()
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("openai/gpt-oss-120b")
tokens = tokenizer("Hello, world!")
Transformers v4 and v5 are supported. Pass
patch_transformers(apply_chat_template=True) to also use the native renderer
for supported render-only apply_chat_template(..., tokenize=False) calls;
unsupported templates automatically fall back to Transformers.
Baseten Tokenizer is focused on inference and does not implement every Hugging Face Tokenizers training or alignment feature.
License
MIT
Metadata
Release files for basetenkenizer 0.2.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 93.7 MB
Release files / basetenkenizer-0.2.8-cp314-cp314t-musllinux_1_2_x86_64.whl
| Download URL | basetenkenizer-0.2.8-cp314-cp314t-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 4.8 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ x86-64 |
|
SHA-256 checksum How to use checksums |
f35e9d1ea1b433fcfa804559e91ff7b9a7b3d163bda7351490fec20651dd7634
|
|
BLAKE2b-256 checksum How to use checksums |
9b27e96e027116a14657e69ade41b0fc32281c91b79241d4f5789ec54b0c5c4b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / basetenkenizer-0.2.8-cp314-cp314t-musllinux_1_2_i686.whl
| Download URL | basetenkenizer-0.2.8-cp314-cp314t-musllinux_1_2_i686.whl |
|---|---|
| Size | 4.7 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ x86-32 |
|
SHA-256 checksum How to use checksums |
9cafa215b511e394685a834e38cbe28fbca6ec467c08dd5ff602ce91ce78f089
|
|
BLAKE2b-256 checksum How to use checksums |
e34400fd0190c55fc9b5302f45ba47e2c77a5d61b8d44fdd5b9b515563a601e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / basetenkenizer-0.2.8-cp314-cp314t-musllinux_1_2_armv7l.whl
| Download URL | basetenkenizer-0.2.8-cp314-cp314t-musllinux_1_2_armv7l.whl |
|---|---|
| Size | 4.4 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ ARMv7l |
|
SHA-256 checksum How to use checksums |
10947213ed80667ef48f4a74142951d617ea7e6be7a6e39fb2d4bbb8e2fe535f
|
|
BLAKE2b-256 checksum How to use checksums |
683152c7524949474b53a87c50e23601452d9e27135223d6ffa50529681cde31
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / basetenkenizer-0.2.8-cp314-cp314t-musllinux_1_2_aarch64.whl
| Download URL | basetenkenizer-0.2.8-cp314-cp314t-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 4.5 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux musl 1.2+ ARM64 |
|
SHA-256 checksum How to use checksums |
48c2f94f797ee1a9a39b9d87193d40db4bafb24bed9bf4d5ee2e812cf9016615
|
|
BLAKE2b-256 checksum How to use checksums |
055f1806aa465cf2a6e5f8ba376fc792eb13d4f24a5d4d639be4cc8c8823c609
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / basetenkenizer-0.2.8-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | basetenkenizer-0.2.8-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 4.4 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
3ba931ef9d73798a130df5c2694a6687341a19dce03a585607aab052cb383c63
|
|
BLAKE2b-256 checksum How to use checksums |
650af0b7c6db0c31f902b6af6f87de87ae60477c1205ea4bf7e7af235b8e6438
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / basetenkenizer-0.2.8-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
| Download URL | basetenkenizer-0.2.8-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl |
|---|---|
| Size | 5.0 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ PowerPC 64-le |
|
SHA-256 checksum How to use checksums |
6b4f029d56a2ee3a8b91f9b2b24ead7df20feba3a165da26ef23213bb3c47c67
|
|
BLAKE2b-256 checksum How to use checksums |
630192a3aebda215ef2e143b04ff9000dccf06371efc02da3a30ce11cc6df984
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / basetenkenizer-0.2.8-cp314-cp314t-manylinux_2_17_i686.manylinux2014_i686.whl
| Download URL | basetenkenizer-0.2.8-cp314-cp314t-manylinux_2_17_i686.manylinux2014_i686.whl |
|---|---|
| Size | 4.7 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading Linux glibc 2.17+ x86-32 |
|
SHA-256 checksum How to use checksums |
fe454efb1f2c0a78044afb6945a6ba3c91d30f4f8c0ab41182886757985bc385
|
|
BLAKE2b-256 checksum How to use checksums |
3e042ef90ba3f034a63385f40e93e562f4990960ef863ff6944ed643371cc17f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / basetenkenizer-0.2.8-cp314-cp314t-macosx_11_0_arm64.whl
| Download URL | basetenkenizer-0.2.8-cp314-cp314t-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.0 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
31044c8114f9cc406fa7bb1f6511b38f308a4c915528d9e4f1c3edc3b5bc2521
|
|
BLAKE2b-256 checksum How to use checksums |
6a18e9eb596f4433b0263f2c2e2ca795af05eefe806108783604d46f81425b96
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / basetenkenizer-0.2.8-cp314-cp314t-macosx_10_12_x86_64.whl
| Download URL | basetenkenizer-0.2.8-cp314-cp314t-macosx_10_12_x86_64.whl |
|---|---|
| Size | 4.1 MB |
| Tags | CPython 3.14 CPython 3.14 free-threading macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
c559b458a7fb14e299f1a3b1c07b35ac9fe75e3f8ccfa6459866091a52f8ee52
|
|
BLAKE2b-256 checksum How to use checksums |
fad908b018b8a9f711a2252215fa8c6dbc3bb0d291dc013c36f145fc812d0c8d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / basetenkenizer-0.2.8-cp310-abi3-win_amd64.whl
| Download URL | basetenkenizer-0.2.8-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 3.7 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
4248b8717a9d6abd8e92948458aa59d73faebab8a169eb46ca15eb518834c34f
|
|
BLAKE2b-256 checksum How to use checksums |
6f1758b3bf0af8a2217cb0b99e86edaf6d557fe35d422c6d599d7dc5f3de22cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / basetenkenizer-0.2.8-cp310-abi3-musllinux_1_2_x86_64.whl
| Download URL | basetenkenizer-0.2.8-cp310-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 4.8 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
6864ce7961b61432cbe2d6df474822dc741c93effeaa28ba52779f21b864164b
|
|
BLAKE2b-256 checksum How to use checksums |
a5bd86ba1d15b2655bb24e11b6d7e5f78164dd43e7ba3b7573e198dd7f56856c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / basetenkenizer-0.2.8-cp310-abi3-musllinux_1_2_i686.whl
| Download URL | basetenkenizer-0.2.8-cp310-abi3-musllinux_1_2_i686.whl |
|---|---|
| Size | 4.7 MB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
c5f302c1830697a94a6862aab656d1f910cdbea939d699fc96ff38aef12e48a5
|
|
BLAKE2b-256 checksum How to use checksums |
455aac6b796f7144cd27649ee5e640a71a8fae3354d6ac68183ee1abb95f3262
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / basetenkenizer-0.2.8-cp310-abi3-musllinux_1_2_armv7l.whl
| Download URL | basetenkenizer-0.2.8-cp310-abi3-musllinux_1_2_armv7l.whl |
|---|---|
| Size | 4.4 MB |
| Tags | CPython 3.10 Linux musl 1.2+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
8254c61321c55e9ddf5660f533601806c7d56f7ba0c6f376ac31b7be1222dea2
|
|
BLAKE2b-256 checksum How to use checksums |
dd1b51706c7932d18cc03db8dd13c5124fe9b0c1734b9cb63ae3d6bf956aedd8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / basetenkenizer-0.2.8-cp310-abi3-musllinux_1_2_aarch64.whl
| Download URL | basetenkenizer-0.2.8-cp310-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 4.5 MB |
| Tags | CPython 3.10 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
17476e23e95550eee7d2f0f3e3b8ce022e67094a90bca8dc47f100184b9acbc8
|
|
BLAKE2b-256 checksum How to use checksums |
0d5dd9bf9fb52e7cad9b01d635092050cf9bf10ff5a6810b5fbdb968afcffbf7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / basetenkenizer-0.2.8-cp310-abi3-manylinux_2_28_ppc64le.whl
| Download URL | basetenkenizer-0.2.8-cp310-abi3-manylinux_2_28_ppc64le.whl |
|---|---|
| Size | 5.0 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ PowerPC 64-le abi3 |
|
SHA-256 checksum How to use checksums |
5042c8e334d0d457a0800248bc67a41278af882a365ae47638f3645861068533
|
|
BLAKE2b-256 checksum How to use checksums |
e30e0f4591f6af4858ceb23c4131a25de34012dcd6c656c98a6721fa72e319f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / basetenkenizer-0.2.8-cp310-abi3-manylinux_2_28_armv7l.whl
| Download URL | basetenkenizer-0.2.8-cp310-abi3-manylinux_2_28_armv7l.whl |
|---|---|
| Size | 4.2 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ ARMv7l abi3 |
|
SHA-256 checksum How to use checksums |
9561f4161c4e9f83693b5bf478bd3ef45e9db40bf10a7cc928d253080444089f
|
|
BLAKE2b-256 checksum How to use checksums |
8b70984520f00ed809ea8e98a1fd8cce6b4c21431774981c609d04f55e6b593f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / basetenkenizer-0.2.8-cp310-abi3-manylinux_2_28_aarch64.whl
| Download URL | basetenkenizer-0.2.8-cp310-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 4.5 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
6a019f3bf96ba6e2c93b500496ea4123e692cf6112cfe0971601b23963d25461
|
|
BLAKE2b-256 checksum How to use checksums |
cfc80baf69219caa8e60945cee6ca4025c7b20c9e257c9d465f33e2422b3a9ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / basetenkenizer-0.2.8-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | basetenkenizer-0.2.8-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 4.4 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
7bbe01584a65baf9d01b90d62b2513b4d4b6831bddca447cdbe6e24da78ae24c
|
|
BLAKE2b-256 checksum How to use checksums |
a9ff5e36b4b0eb1a5bd9160e14f7ab7eb0e5a02a505743dd328febe1a545c87f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / basetenkenizer-0.2.8-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl
| Download URL | basetenkenizer-0.2.8-cp310-abi3-manylinux_2_17_i686.manylinux2014_i686.whl |
|---|---|
| Size | 4.7 MB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-32 abi3 |
|
SHA-256 checksum How to use checksums |
05f1ac7aa8f6edd326457fd305cda2a78c6180d8b07a52e423dde19a67196887
|
|
BLAKE2b-256 checksum How to use checksums |
6abfcbc57612c7b19fe6842035cfaf7cd7a0beab1d22a95f956656c6f199350e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / basetenkenizer-0.2.8-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | basetenkenizer-0.2.8-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 4.0 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
52d677bf7bf61fb25d2e71f090014ef8c80ab050264c0db8c66928a64fef287a
|
|
BLAKE2b-256 checksum How to use checksums |
418fe6671af8d53adb902ce7896b777af77f2b56c7322c9359eaafee5048e944
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Release files / basetenkenizer-0.2.8-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | basetenkenizer-0.2.8-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 4.1 MB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
b3c7a23835f9639e8fc776ca9ec2c2480ba016db38b9dab5dbadd1af735a22ca
|
|
BLAKE2b-256 checksum How to use checksums |
1e015b1313cd552e18be10e470162cd59de75c5bf0896c882205409abb925f68
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.14.1
|
Security for basetenkenizer 0.2.8
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.