Skip to main content

toknroll

Token-perfect LLM tokenization for Python. Each model's own tokens, id for id, faster than Hugging Face tokenizers and tiktoken.

PyPI Python License

Encoding speed on six models: toknroll ahead of Hugging Face tokenizers 1.0 rc4 and 0.23.3 and of tiktoken

pip install toknroll
import toknroll

tokenizer = toknroll.load("Qwen/Qwen3-0.6B")    # fetched once, never the weights
ids = tokenizer.encode("Hello, world!")          # array('i', [9707, 11, 1879, 0])
tokenizer.decode(ids)                            # 'Hello, world!'
tokenizer.count_tokens("Hello, world!")          # 4
tokenizer.encode_batch(["Hello", "world"])       # spread over every core
  • Exact. The same ids as each model's own tokenizer, verified by parity tests against Hugging Face tokenizers, llama.cpp and tiktoken.
  • Fast. 125-195 MB/s of text on one core for Qwen, Llama, gpt-oss and DeepSeek, every core with encode_batch, and the GIL released on every call.
  • Light. One 6 MB wheel with no dependencies: no torch, no transformers, no compiler.

What it reads

toknroll.load reads a tokenizer.json or its folder, a GGUF file (its header only, never the weights), or a tiktoken checkout, on disk or by Hugging Face or ModelScope reference (owner/repo[@rev][:quant]), fetched once and cached; a URL is refused; the error shows the reference to use instead. Parity is tested on the tokenizers of 18 vendors' models, Qwen, Llama, Gemma 4, gpt-oss, DeepSeek, Mistral, Granite, Kimi and more; a tokenizer toknroll cannot reproduce exactly is refused at load, never approximated.

Requirements

  • Python 3.10 or later, and no other package.
  • Linux x86-64 or aarch64 with glibc 2.28 or later, macOS 14 or later on Apple silicon, or Windows 10 or later on x86-64.
  • On x86-64, a CPU with AVX2.
  • curl on the PATH for Hub sources; a local file needs nothing.

The API at a glance

You want Call
ids encode(text), an array('i') numpy reads without a copy; specials=True keeps special tokens whole
text decode(ids), or decode_bytes(ids) for the exact bytes
a count count_tokens(text)
many texts encode_batch(texts)
the vocabulary vocabulary_size, token(id), id(token)

The full API reference covers every call, sources, errors, the cache and the C library.

License

Apache 2.0, by Quixotic AI. The library in the wheel is built with Oracle GraalVM and carries its runtime under the GraalVM Free Terms and Conditions: free to use, commercially too, but a product sold for a fee that bundles it is not covered.

Metadata

Release files for toknroll 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for toknroll 0.4.0
File Actions
toknroll-0.4.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for toknroll-0.4.0-py3-none-win_amd64.whl
toknroll-0.4.0-py3-none-manylinux_2_28_x86_64.whl Python 3 none Linux glibc 2.28+ x86-64 Details for toknroll-0.4.0-py3-none-manylinux_2_28_x86_64.whl
toknroll-0.4.0-py3-none-manylinux_2_28_aarch64.whl Python 3 none Linux glibc 2.28+ ARM64 Details for toknroll-0.4.0-py3-none-manylinux_2_28_aarch64.whl
toknroll-0.4.0-py3-none-macosx_14_0_arm64.whl Python 3 none macOS 14.0+ ARM64 Details for toknroll-0.4.0-py3-none-macosx_14_0_arm64.whl

Total release size: 23.0 MB

Release files / toknroll-0.4.0-py3-none-win_amd64.whl

Download URL toknroll-0.4.0-py3-none-win_amd64.whl
Size 6.0 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
5485301be562df8af642416f813946c46c4d9e9cc208a8ad3e601978bd99205d
BLAKE2b-256 checksum
How to use checksums
4409e86b78288f3028a2913231a19644d5b065a5b911ef93f467e78ee434c267
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / toknroll-0.4.0-py3-none-manylinux_2_28_x86_64.whl

Download URL toknroll-0.4.0-py3-none-manylinux_2_28_x86_64.whl
Size 5.7 MB
Tags Linux glibc 2.28+ x86-64 Python 3
SHA-256 checksum
How to use checksums
b0fef0acf95e2377b915b11042b83198e8c47168942480a5ba3c09dde10f39bd
BLAKE2b-256 checksum
How to use checksums
7aaf795627d833acab5551dc076cbf1f963eaa8bc85a1fde1a19192ca631752e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / toknroll-0.4.0-py3-none-manylinux_2_28_aarch64.whl

Download URL toknroll-0.4.0-py3-none-manylinux_2_28_aarch64.whl
Size 5.6 MB
Tags Linux glibc 2.28+ ARM64 Python 3
SHA-256 checksum
How to use checksums
54eba9df94d1b0d2a06717f3a5dd5aaf00046338c31915aa5d7863d7b32df2b9
BLAKE2b-256 checksum
How to use checksums
78b2b353f4bfd651f670f17b19b23e2e055750058bd368e508badc10081fa608
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / toknroll-0.4.0-py3-none-macosx_14_0_arm64.whl

Download URL toknroll-0.4.0-py3-none-macosx_14_0_arm64.whl
Size 5.7 MB
Tags Python 3 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
1318a0604d726b959ca548f7249c92c95bd0d256908ab8f65debe4bf67d06c9c
BLAKE2b-256 checksum
How to use checksums
04cb6e6eec6f6d271b3ad8c82d2546a68a3c9337207fc82239985694d9d614e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for toknroll 0.4.0

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.

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