A terminal-based GPT token visualiser built on tiktoken.
Project description
GPT-Tokenizer
A terminal-based GPT token visualiser. Type text into an interactive REPL and each token is printed on a colored background so you can see exactly where the tokenizer splits your input. Backed by tiktoken.
Install
Requires Python 3.10+.
python -m venv .venv
source .venv/bin/activate
pip install -e .
Usage
gpt-tokenizer # console entry point
# or
python -m gpt_tokenizer
Type text at the prompt and press Enter to tokenize it. To write multiple lines or paragraphs, press Shift+Enter (or Option/Alt+Enter) to insert a newline without submitting — the whole block is tokenized together. Press Ctrl-D to quit.
Shift+Enter relies on your terminal reporting it as a distinct key (iTerm2, kitty, WezTerm, and the VS Code terminal do; macOS Terminal.app does not). Option/Alt+Enter works everywhere.
A line on its own starting with / is a command (runs on Enter):
| Command | Action |
|---|---|
/model |
Switch model (gpt2, gpt-3.5-turbo, gpt-4, gpt-4o) |
/clear |
Clear the screen and redraw the banner |
/help |
Show the command list |
/bye |
Exit (or Ctrl-C, or Ctrl-D on an empty prompt) |
Newlines in your text are shown as a dim ⏎ glyph so the original layout stays
visible. The default model is gpt-4o.
Project layout
src/gpt_tokenizer/ Installable package
cli.py REPL loop and command dispatch
tokenizer.py tiktoken encode wrapper -> list of (id, bytes)
models.py Supported models + interactive selection
render.py Banner and colorized token output
ansi.py ANSI escape-sequence helpers
examples/
bpe_from_scratch.py Standalone, educational BPE walkthrough (Karpathy minbpe style)
data/ GPT-2 encoder.json / vocab.bpe (used only by the example)
tests/ pytest suite
Development
pip install -e ".[dev]" # installs pytest
pytest
pip install -e ".[examples]" # installs regex, needed by the BPE example
python examples/bpe_from_scratch.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gpt_tokenizer-1.0.0.tar.gz.
File metadata
- Download URL: gpt_tokenizer-1.0.0.tar.gz
- Upload date:
- Size: 566.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2685646fd07391cb71662c95a75d3c1c2850c8f22132ac5f0092bf6914d2031c
|
|
| MD5 |
c3af4a576432d634a25bee2598236a75
|
|
| BLAKE2b-256 |
b81d12f6366a65b76dfb199cd46c10bc65c6eee4e1332b282ba0fa395d1cf801
|
File details
Details for the file gpt_tokenizer-1.0.0-py3-none-any.whl.
File metadata
- Download URL: gpt_tokenizer-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8a9a9033643a3124f37aa24ac176c7c12775ff47f374189360cb5c9d6b1847c
|
|
| MD5 |
f834c17aedf95359ff6625a257c8b478
|
|
| BLAKE2b-256 |
7f4ea42b36dffb161b5d2bedd2f8acfdf4d41555164cdc298b590238a3bf6892
|