Skip to main content

gotoken

Syntax-aware tokenizer for Bash and formal languages, written in Rust with Python bindings.

Why gotoken?

Standard BPE tokenizers (tiktoken, HuggingFace) fragment Bash constructs like 2>&1, &&, --help into 4-5 separate tokens, wasting context window and model parameters.

gotoken protects 130+ shell operators, coreutils commands and flags as atomic single tokens, then falls back to byte-level encoding for everything else.

Features

  • grep, chmod, find, 2>&1, &&, ||, -rf → single ID, always
  • Zero OOV: every byte maps to a fallback ID in [1000..1255]
  • Perfect round-trip: decode(encode(s)) == s guaranteed
  • VOCAB_SIZE = 32768 (power-of-two, Tensor Core aligned)
  • Rayon parallel batch encoding, GIL released during tokenization
  • Python 3.9+ via PyO3, installable with pip install gotoken

Install

pip install gotoken       # Python
cargo add gotoken         # Rust

Usage (Python)

from gotoken import GoToken

tok = GoToken()

ids  = tok.encode("grep -rf /tmp 2>&1")
text = tok.decode(ids)
assert text == "grep -rf /tmp 2>&1"

# Parallel batch — GIL released, rayon saturates all cores
results = tok.encode_batch(["find /var -name '*.log'", "chmod 755 /bin/app"])

Usage (Rust)

use gotoken::encoder::Encoder;

let enc  = Encoder::new();
let ids  = enc.encode_str("grep -rf /tmp 2>&1", false)?;
let text = enc.decode(&ids)?;
assert_eq!(text, "grep -rf /tmp 2>&1");

Compression vs tiktoken

Command tiktoken tokens gotoken tokens
grep -r 'TODO' . 2>&1 12 7
chmod 755 /var/www/html 10 6
find /home -name '*.log' | wc -l 14 8

License

MIT

Release files for gotoken 0.1.1

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

Source distribution (sdist)

Source distribution for gotoken 0.1.1
File Size Uploaded
gotoken-0.1.1.tar.gz 30.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gotoken 0.1.1
File Interpreter ABI Platform
gotoken-0.1.1-cp313-cp313-manylinux_2_34_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.34+ x86-64 Details

Total release size: 782.9 kB

Release files / gotoken-0.1.1.tar.gz

Download URL gotoken-0.1.1.tar.gz
Size 30.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c8dd20b17da5de27f600176fed96d00903e1b39512450e85d19ea9ed453544d0
BLAKE2b-256 checksum
How to use checksums
88ab563cb5ba07f685c93ebda13c61d020ec7154818b6f098892f1e1bc411661
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.0

Release files / gotoken-0.1.1-cp313-cp313-manylinux_2_34_x86_64.whl

Download URL gotoken-0.1.1-cp313-cp313-manylinux_2_34_x86_64.whl
Size 752.9 kB
Tags CPython 3.13 Linux glibc 2.34+ x86-64
SHA-256 checksum
How to use checksums
e809f8222cbcb375794d9512b992d5db8551b4147af76d7941811c3f0a31a5c7
BLAKE2b-256 checksum
How to use checksums
0ac55cef752ff2e03790181dd06d2a08cc541d4eb7738efc05c04d092874c855
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via maturin/1.14.0

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

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