Metadata-Version: 2.4
Name: tokie
Version: 0.2.0
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Text Processing
Classifier: Topic :: Text Processing :: Linguistic
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Development Status :: 4 - Beta
Classifier: Operating System :: OS Independent
Classifier: Typing :: Typed
Requires-Dist: numpy
Summary: Blazingly fast tokenizer — 50x faster, 10x smaller, 100% accurate
Keywords: tokenizer,tokenization,bpe,wordpiece,sentencepiece,bert,gpt2,llama,nlp,embedding,rag,transformers,huggingface,fast,rust
License: MIT OR Apache-2.0
Requires-Python: >=3.10
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Bug Tracker, https://github.com/feyninc/tokie/issues
Project-URL: Documentation, https://docs.rs/tokie
Project-URL: Homepage, https://github.com/feyninc/tokie
Project-URL: Repository, https://github.com/feyninc/tokie

<p align="center">
  <img src="https://raw.githubusercontent.com/feyninc/tokie/main/assets/tokie-banner.png" alt="tokie">
</p>

<p align="center">
  <a href="https://github.com/feyninc/tokie">GitHub</a> · <a href="https://crates.io/crates/tokie">crates.io</a>
</p>

Python bindings for the tokie 0.2 tokenizer. `encode`, `encode_plus`, and `batch` release the GIL and return NumPy arrays. There is no `Encoding` object and no `.ids` attribute; use `.tolist()`.

## Installation

```bash
pip install tokie
```

## Quick start

```python
import tokie

tokenizer = tokie.Tokenizer.from_pretrained("openai-community/gpt2")
# from_json(path) and from_file(path) are aliases for open(path).

ids = tokenizer.encode("Hello world")            # uint32 array, template off
print(ids.tolist())
print(tokenizer.decode(ids.tolist()))
print(tokenizer.decode_bytes(ids.tolist()))      # raw bytes

# The single-sequence template. GPT-2 has none, so this matches encode.
print(tokenizer.encode_plus("Hello world").tolist())

flat, ends = tokenizer.batch(["Hello world", "a12b"])  # ends are cumulative
print(tokenizer.count_tokens("Hello world"))           # template off
print(tokenizer.count_tokens_batch(["Hello world", "a12b"]))
print(tokenizer.vocab_size)                            # highest id + 1
print(tokenizer.pad_token_id)                          # [PAD] then <pad>
print(tokenizer.num_special_tokens_to_add(is_pair=False))
tokenizer.save("gpt2.tokie")
```

`encode` leaves the template off. `encode_plus` applies it and accepts `pair`, `truncate`, and `pad`; truncation is from the right, longest sequence first, and padding is fixed on the right. One `max_len` covers both and counts the template ids.

`from_pretrained` opens exactly one `.tokie` file from the repo, whatever its name. A repo with no `.tokie` file is parsed from `tokenizer.json`; several `.tokie` files is an error. There is no runtime `.tkz` fallback: a genuine legacy `TOKI` image is refused by magic, not by extension, while a JSON file merely named `.tkz` is parsed as JSON. `open` reads either file from disk by its magic, `from_json(path)` and `from_file(path)` are path aliases for `open`, and `json(text)` parses JSON text.

`decode` returns `str` (lossy only where needed). `decode_bytes` returns raw bytes. Both keep specials by default; `skip=True` omits them. `get_vocab()` returns raw token strings and may have fewer entries than `vocab_size`.

## Benchmark

`bench.py` times `Tokenizer.encode` on one file against the `tokie bench` command, which is the Rust path.

## License

MIT OR Apache-2.0

