tokenx-rs
Library Listed
Fast token count estimation for LLMs at 96% accuracy without a full tokenizer
- Downloads
- 1,235
- Dependents
- 3
- Stars
- 3
- Forks
- 1
- Contributors
- 1
- Commits
- 5
- Latest release
- 0.1.0 ·
About
Rust port of tokenx by Johann Schopplich
Fast token count estimation for LLMs at 96% accuracy without a full tokenizer.
Why?
- No vocabulary files: Full tokenizers like tiktoken require 2-4MB of BPE vocabulary data
- Zero dependencies: No regex, no allocations — just a single-pass character scanner
- Fast: ~8x faster than the original Node.js implementation on Latin text
- Accurate enough: 96% accuracy is sufficient for token budget estimation and streaming display
- Universal: Works across all LLM providers (OpenAI, Anthropic, Google, etc.)
Installation
[dependencies]
tokenx-rs = "0.1"
Usage
use tokenx_rs::estimate_token_count;
let tokens = estimate_token_count("Hello, world!");
println!("Estimated tokens: {}", tokens);
Check token limits
use tokenx_rs::is_within_token_limit;
if is_within_token_limit(prompt, 4096) {
// safe to send
}
Split text into chunks
use tokenx_rs::split_by_tokens;
let chunks = split_by_tokens(long_text, 1000);
How it works
The estimator makes a single pass over the input string, classifying each character and grouping runs of similar characters into segments. Each segment is scored by type:
Read the full README
| Segment Type | Rule |
|---|---|
| Whitespace | 0 tokens |
| CJK characters | 1 token per character |
| Digit sequences | 1 token |
| Short words (≤3 bytes) | 1 token |
| Punctuation runs | ceil(len / 2) |
| Alphanumeric words | ceil(len / chars_per_token) |
| Other (emojis, mixed) | 1 token per character |
Language-specific diacritics (German, French, Spanish) adjust the chars_per_token ratio for more accurate estimates on non-English text.
There is no regex, no string splitting allocation, and no runtime dependencies.
Performance
Benchmarked against the original tokenx Node.js library on the same machine (Apple Silicon, Node v20, rustc 1.91):
| Input | tokenx (Node.js) | tokenx-rs (Rust) | Speedup |
|---|---|---|---|
| Short text (~9 words) | 830 ns | 107 ns | 7.8x |
| Medium text (~900 words) | 89.6 µs | 10.9 µs | 8.2x |
| Long text (~27k words) | 2.91 ms | 332 µs | 8.8x |
| CJK text (1200 chars) | 6.34 µs | 4.04 µs | 1.6x |
| Code (~100 fn blocks) | 443 µs | 52.9 µs | 8.4x |
Run benchmarks yourself with cargo bench.
Accuracy
Accuracy benchmarks from the original tokenx project (compared against tiktoken cl100k_base):
| Content | Actual Tokens | Estimated | Deviation |
|---|---|---|---|
| Short English text | 19 | 19 | 0.00% |
| German text with umlauts | 48 | 49 | 2.08% |
| Kafka - Metamorphosis (English) | 31,796 | 32,325 | 1.66% |
| Kafka - Die Verwandlung (German) | 35,309 | 33,970 | 3.79% |
| 道德經 - Laozi (Chinese) | 11,712 | 11,427 | 2.43% |
| 羅生門 - Akutagawa (Japanese) | 9,517 | 10,535 | 10.70% |
| TypeScript ES5 declarations | 49,293 | 51,599 | 4.68% |
License
MIT
Compatibility
- Runs on
- GPU support unknown
What shows it
- no dependency or feature matches a backend row
- Native code
- None found
- No native code found
- Python bindings
- No Python binding crate found
- License
- MIT
Compare with similar projects
Order: strongest tier first, then most downloads, then name, with unmeasured values last. A library counts downloads over 30 days. An app counts binary downloads per release. An app with none counts its crate downloads over 30 days. ML Rust runs this catalogue, so its closest project always gets a row.
| Project | Downloads | Dependents | Stars | Latest release | Runs on (GPU) | Native code | License |
|---|---|---|---|---|---|---|---|
|
Fast token count estimation for LLMs at 96% accuracy without a full tokenizer |
1,235 downloads over 30 days | 3 | 3 | 0.1.0 | GPU support unknown | No native code found | MIT |
|
whatlang-rs Featured
Fast and lightweight language identification library for Rust. |
882,019 downloads over 30 days | 74 | 1,087 | 0.18.0 | GPU support unknown | No native code found | MIT |
|
whichlang Listed
A blazingly fast and lightweight language detection library for Rust. |
52,880 downloads over 30 days | 11 | 464 | 0.1.1 | GPU support unknown | No native code found | MIT |
|
sentencepiece Listed
Binding for the sentencepiece tokenizer |
30,249 downloads over 30 days | 18 | 24 | 0.14.0 | GPU support unknown | Binds native code: sentencepiece-sys. Build uses a native toolchain: cc, cmake, pkg-config | Apache-2.0 OR MIT |
|
splintr Listed
Tokenizer for Rust and Python: pure Rust by default, with 18 bundled vocabularies and four backends covering BPE, SentencePiece and WordPiece. Its output matches Hugging Face tokenizers id for id on 14 model families, including GPT-2, Qwen, Whisper, T5 and BERT. Python bindings |
8,204 downloads over 30 days | 7 | 63 | 0.22.2 | GPU support unknown | Binds native code: pcre2-sys (feature pcre2) | MIT |
|
kitoken Listed
Fast tokenizer for language models, supporting BPE, Unigram and WordPiece tokenization |
2,949 downloads over 30 days | 3 | 62 | 0.11.1 | GPU support unknown | No native code found | BSD-2-Clause |
|
tokie Listed
Blazingly fast tokenizer - 50x faster tokenization, 10x smaller model files, 100% accurate drop-in replacement for HuggingFace |
711 downloads over 30 days | 3 | 56 | 0.1.4 | GPU support unknown | No native code found | Apache-2.0 OR MIT |
Why ListedNo archive, New or Featured rule places it, so it is Listed.
What it lacks for Featured
- It has 3 active dependents and 3 new dependents in 365 days. Featured needs 11 active dependents or 9 new dependents in 365 days. The repository route reads 3 stars, 1 fork and 1 contributor. It needs 4,539 stars, 434 forks and 79 contributors together.
What else the check found
- The last activity is on 6 Feb 2026, 276 days ago. The rules expect an update within 365 days. Dormancy rule
Exact rules: Listed, Featured library. The check on applied thresholds version 9.
Every rule outcome, as the check records it
expected-interval: version 0.1.0 base 80, capped at 1 releases = 50, raised to the 365-day floor: E = 365 daysdormancy: last activity 2026-02-06, 276 days ago, E = 365: activefeatured: not featured: active_users 3 < 11 and new_adopters 3 < 9 and repository route stars 3 (needs 4539), forks 1 (needs 434), contributors 1 (needs 79)listed: listed: no archive, new or featured rule applies
Measurements and sources
Each signal row shows the raw value, its source and the fetch date. The Sources list gathers every distinct source on this page. Movement needs more history.
Sources6 sources
- Description: the crates.io description
- crates.io database dump, fetched
- RustSec advisory database, fetched
- GitHub repository, fetched
- crates.io package, fetched
- GitHub contributors, fetched
Adoption3 active dependents, 3 new dependents in 365 days1 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Active dependents | 3 | crates.io database dump | Yes | |
| New dependents (365 days) | 3 | crates.io database dump | Yes | |
| Peak active dependents | 3 | crates.io database dump | Yes | |
| Active dependents as a share of the peak | 1 | crates.io database dump | Yes | |
| Binary downloads per release | Not measured | Yes |
MaintenanceLatest human commit: 9 months ago3 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Latest human commit | 2026-02-06 | GitHub repository | Yes | |
| Latest release | 2026-02-06 | crates.io database dump | Yes | |
| First release | 2026-02-06 | crates.io database dump | Yes | |
| Latest version | 0.1.0 | crates.io database dump | Yes | |
| Days the oldest outside issue waits for a reply | 117 | GitHub repository | Yes | |
| Maintainer replies over 365 days | 0 | GitHub repository | Yes | |
| Repository archived | false | GitHub repository | Yes | |
| Repository gone | false | GitHub repository | Yes | |
| Release commit or manifest in the repo | true | crates.io package | Yes | |
| Published docs | true | crates.io database dump | Yes | |
| Latest release fails cargo check | Not measured | Yes | ||
| Build check date | Not measured | Yes | ||
| Build check toolchain | Not measured | Yes |
SecurityUnpatched vulnerabilities: none
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Unpatched vulnerabilities past the grace window | none | RustSec advisory database | Yes | |
| RustSec unmaintained advisory | none | RustSec advisory database | Yes | |
| Deprecation notice | none | crates.io database dump | Yes | |
| Deprecated requirement | none | crates.io database dump | Yes |
Distribution1 releases, 1,235 downloads over 30 days5 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Releases | 1 | crates.io database dump | Yes | |
| Downloads over 30 days | 1235 | crates.io database dump | Yes | |
| Binary downloads over the last 3 releases | Not measured | Yes | ||
| Homebrew installs on request over 365 days | Not measured | Yes | ||
| Repology repository families | Not measured | Yes | ||
| Docker pull growth over 90 days | Not measured | Yes | ||
| Docker pulls at the growth baseline | Not measured | Yes | ||
| Every version a prerelease | false | crates.io database dump | Yes | |
| Every version 0.0.x | false | crates.io database dump | Yes | |
| Every version yanked | false | crates.io database dump | Yes | |
| Crate deleted from crates.io | false | crates.io database dump | Yes |
Repository3 stars, 1 forks, 1 contributors, 5 commits. Stars alone never qualify a project.
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| GitHub stars | 3 | GitHub repository | Yes — one part of the repository route | |
| GitHub forks | 1 | GitHub repository | Yes — one part of the repository route | |
| Contributors with a GitHub account | 1 | GitHub contributors | Yes — one part of the repository route | |
| Commits on the default branch | 5 | GitHub repository | No | |
| Repository's main crate left out of the entry | none | crates.io database dump | Yes |
Facts that never count
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| License | MIT | crates.io database dump | No | |
| Runs on, from listed crates and their direct dependencies | GPU support unknown | crates.io database dump | No | |
| What shows each backend | no dependency or feature matches a backend row | crates.io database dump | No | |
| Native code, from listed crates and their dependencies | No native code found | crates.io database dump | No | |
| Python bindings, from direct dependencies of listed crates | No Python binding crate found | crates.io database dump | No | |
| Crates that depend on a listed crate directly | 3 | crates.io database dump | No |
Corrections and review history
No correction applies to this entry.
Judgments
A judgment enters only through an approved issue and a merged pull request.
No judgment applies to this entry.