Skip to main content

tokforge

Fast BPE tokenization for Python, backed by a Rust engine.

GPT-2, GPT-4 (cl100k_base), GPT-4o (o200k_base) and Qwen2-style tokenizers run on a byte-level BPE core written from scratch, checked against tiktoken and Hugging Face tokenizers by differential tests and long soak runs without a mismatch. On public text it runs at about tiktoken's speed on one thread and ahead of it in batches, with identical output. Any other Hugging Face tokenizer.json (BERT, XLM-R, ...) loads too and runs on the Hugging Face backend.

import tokforge

tok = tokforge.Tokenizer.from_file("tokenizer.json")

tok.encode("hello world")              # [31373, 995]
tok.count("hello world")               # 2
tok.decode([31373, 995])               # "hello world"
tok.encode_batch(["a", "b", "c"])      # parallel, releases the GIL
tok.truncate(long_text, 512)           # a prefix of long_text within 512 tokens
tok.chunk(long_text, 512)              # slices that join back to long_text

Options, all keyword-only:

  • special_tokens="literal" (default) treats spellings like <|endoftext|> in the input as plain text; "recognize" matches them as special tokens.
  • add_special_tokens=False (default); True adds the model's BOS/EOS tokens.
  • core="auto" (default) uses the custom core where it applies; "backend" forces the Hugging Face path; "verify" runs both and raises if they ever disagree.

Errors raise ValueError (bad options, unknown ids, invalid input) or OSError (file).

License: MIT OR Apache-2.0.

Metadata

Release files for tokforge 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 tokforge 0.1.1
File Size Uploaded Provenance Actions
tokforge-0.1.1.tar.gz 747.9 kB With provenance Details for tokforge-0.1.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for tokforge 0.1.1
File Actions
tokforge-0.1.1-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for tokforge-0.1.1-cp39-abi3-win_amd64.whl
tokforge-0.1.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for tokforge-0.1.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
tokforge-0.1.1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for tokforge-0.1.1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
tokforge-0.1.1-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for tokforge-0.1.1-cp39-abi3-macosx_11_0_arm64.whl
tokforge-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for tokforge-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 10.2 MB

Release files / tokforge-0.1.1.tar.gz

Download URL tokforge-0.1.1.tar.gz
Size 747.9 kB
Tags Source
SHA-256 checksum
How to use checksums
11a8e50b941facf8b8e3f1191738cbf4e8c482ed94e55026d61e36a31aba2ccb
BLAKE2b-256 checksum
How to use checksums
467d306afbab59e40eef692bb52a363d4942dc252bf17ea1e94f33195e9d3c32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / tokforge-0.1.1-cp39-abi3-win_amd64.whl

Download URL tokforge-0.1.1-cp39-abi3-win_amd64.whl
Size 1.8 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
26622e4ed40aa7457e25d41e926cffb23953e922d1c1009fea7e32bcabe86f2d
BLAKE2b-256 checksum
How to use checksums
57e362ace4e6b90f4f8c840b1732be0cac2a4de5cfe135ff4e109cbc66e2a8ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / tokforge-0.1.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL tokforge-0.1.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 2.0 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
f6030d76d2f9a7b111fc836a340d54a660ae4fcf90c36b4e4299d3a5f3109709
BLAKE2b-256 checksum
How to use checksums
8fe0de95d159291f08457d2c50d26d1f0ab0463af7a8458f9e495cff2dc8dfae
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / tokforge-0.1.1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL tokforge-0.1.1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 2.0 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
9a2c17e88f6a6b4508fda0e76fa80861279f926558f21873af3cfc2c83f38c28
BLAKE2b-256 checksum
How to use checksums
82e1106514e1e498e962d99a0e26654fb3d7393854898fafd9978150e9117dc4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / tokforge-0.1.1-cp39-abi3-macosx_11_0_arm64.whl

Download URL tokforge-0.1.1-cp39-abi3-macosx_11_0_arm64.whl
Size 1.8 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
1680cefde677dcf24629d4659da16200eabd13fa0028e548913296d582a2b6c0
BLAKE2b-256 checksum
How to use checksums
516f3b5e6dc24f720237ed1d4f242652d90230048c545368b70ce6276df152d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Release files / tokforge-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl

Download URL tokforge-0.1.1-cp39-abi3-macosx_10_12_x86_64.whl
Size 1.9 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
e1d8fd31cc662acbe76361c9e0ddd34d83aeea3dbb07c144dd53a403a8725e93
BLAKE2b-256 checksum
How to use checksums
94dd7e304ba066d8fd7bf9f1e47d0f271ab456fcd747afbb1e3b10aa1c2c923b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

Security for tokforge 0.1.1

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.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for tokforge-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 13, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

6 release files Full provenance

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