Skip to main content

tokens.md

The Vision of the Colosseum. The last martyr by José Benlliure y Gil - 1885

Tokens.md is my tool for saving tokens when speaking to chatbots by converting files en-masse to Markdown. It turns PDFs, Office documents, e-books, structured data, HTML, web pages, and whole code repositories into clean, token-efficient Markdown you can paste straight into an LLM.

OpenAI's tiktoken is used to estimate how many tokens are saved (pretty accurately). In some preliminary results, this conversion is usually anywhere between 60% and 95% of tokens saved (smaller files benefit "more" since a larger proportion of their data is overhead).

Outline

Features

The features of this tool are all encompassed by the tmd CLI commands. The front end displays this with an accessible GUI.

  • tmd convert: convert files to Markdown.
  • tmd clip: convert files to markdown and copy the result to your clipboard.
  • tmd watch: watch a hot folder and auto-convert new files as they appear.
  • tmd fetch: pull a web page and save clean article Markdown.
  • tmd repo: collapse an entire code repository into a single Markdown manifest.
  • tmd merge: combine many files into one master document with a Table of Contents.
  • tmd delta: show how many tokens were saved.
  • --budget: an extra argument to force output size in tokens.

See the usage guide for examples

Install

Pre-Game

First, make sure you have Python 3.13+, uv, and TypeScript support on your machine. Clone this repository:

git clone https://github.com/intelligent-username/tokens.md

And create the environment:

uv venv --python=3.13 .venv

# On Linux or Mac
source .venv/bin/activate

# On Windows
.venv\Scripts\activate

uv pip install -e .               # editable install (provides `tmd`)

To update dependencies, just run uv sync.

Or install the runtime dependencies directly:

uv pip install -r requirements.txt

Running

Quick lil demo

You can run tokens.md in three distinct ways depending on your workflow preference. Here they are, ordered from easiest to hardest to use.

1. Simple Script Execution (python src/main.py)

If you want to run the program directly without installing it as a package, run src/main.py using your Python interpreter:

python src/main.py

You can pass standard CLI arguments directly to the script:

python src/main.py convert input/ -o output/

Both bare tmd and python src/main.py automatically resolve default input/ and output/ folders relative to the project root.

2. Web Front End (tmd ui & Next.js)

The single-page web interface wraps all tmd capabilities into an intuitive side-by-side visual workbench featuring drag-and-drop file upload, URL fetching, clipboard copying, and token budgeting.

Method A: Single CLI Command (tmd ui)

uv pip install -e ".[web]"
tmd ui

This launches the backend server on http://127.0.0.1:8642 and opens your browser.

Note: tmd ui automatically looks for built static assets inside tmd_ui_static/ (installed package source) or frontend/out/ (local repository source). If found, it serves both the REST API and the frontend directly on http://127.0.0.1:8642 as a single unified process.

Method B: Standalone Development Servers If you are developing or modifying the React/Next.js interface and want hot-reloading:

  1. Start the FastAPI backend server:
    python -m backend
    
  2. In a separate terminal, start the Next.js development server:
    cd frontend
    npm install
    npm run dev
    
  3. Open http://localhost:3000 in your web browser. (The Next.js dev server proxies API calls to http://127.0.0.1:8642).

3. CLI Usage (tmd)

After installing via pip install -e ., the tmd command is registered in your environment.

Navigate to the folder containing the files you want to convert and run the following commands. You may manipulate sub-folders and file names, or omit them to use the defaults.

# Convert all supported files in current repository and write to out/ folder
tmd convert . --loc="out"

# Convert current folder into current directory
tmd convert . --loc

# Bare `tmd` command uses default input/ and output/ directories
tmd

# Other CLI subcommands
tmd merge input/ -o output/merged.md
tmd fetch https://example.com/article -o output/article.md
tmd repo . -o output/repo.md

Development

Install dev dependencies and run the test suite and linters:

uv pip install -e ".[dev]"

Testing

Backend (pytest):

pytest                           # Run tests with coverage report
pytest --cov-report=html         # Generate HTML coverage report in htmlcov/

Frontend (vitest):

cd frontend
npm install                       # First-time setup
npm test                          # Run tests once with coverage
npm run test:watch                # Watch mode for development

Run both test suites in parallel with a unified coverage summary:

tmd test                          # Run both backend and frontend test suites
python scripts/test.py            # Direct script invocation
tmd test -v                       # Verbose: full test output

Linting

python scripts/lint.py            # Cross-platform: Ruff + Prettier + ESLint
.\scripts\lint.ps1                # Windows PowerShell script
python scripts/lint.py --fix      # Auto-fix linter and formatting errors

Testing PyPI Releases in Isolated Docker Sandbox

To test installed PyPI releases in an ephemeral state, take the following steps:

# Launch disposable Python container
docker run --rm -it python:3.12-slim bash

# Inside the container shell:
pip install pipx
pipx install tokens-md
pipx ensurepath
export PATH="$HOME/.local/bin:$PATH"

# Test the tmd executable
tmd --version
tmd --help

# More commands...
exit

Exiting the shell (exit) automatically destroys the container and leaves zero footprint on your system. These steps can be done in a permanent environment as well (a real docker container or native install), but pipx won't be performing a native install.

Note on pipx vs pip:

  • pipx install tokens-md: Recommended for global CLI use—installs tmd as an isolated system-wide executable without needing an active virtualenv.
  • pip install tokens-md (or uv pip install tokens-md): Best when working inside an active Python virtual environment where you want tmd registered directly in that environment's PATH.

Documentation

License

This project is licensed under the GNU AFFERO GENERAL PUBLIC LICENSE. See more here

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tokens_md-0.0.13.tar.gz (769.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tokens_md-0.0.13-py3-none-any.whl (109.0 kB view details)

Uploaded Python 3

File details

Details for the file tokens_md-0.0.13.tar.gz.

File metadata

  • Download URL: tokens_md-0.0.13.tar.gz
  • Upload date:
  • Size: 769.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tokens_md-0.0.13.tar.gz
Algorithm Hash digest
SHA256 b8d5a51bece6f6efe929f607a2af830c65053b32c4bb7388e64c81d49e7af67d
MD5 c0bc164849401431c89ad3d75887e3ff
BLAKE2b-256 79b882dbb64cbbdc2151cc1d5f1585665feb3e5c383c70aae3439df9465fb447

See more details on using hashes here.

File details

Details for the file tokens_md-0.0.13-py3-none-any.whl.

File metadata

  • Download URL: tokens_md-0.0.13-py3-none-any.whl
  • Upload date:
  • Size: 109.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for tokens_md-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 8c1f00f2dc32a48d5baa6373f840e24e559d36c1697590889aac1d1c83a8d541
MD5 8d937a46ab27438a0096494f067126a0
BLAKE2b-256 12a9b9353abf03d920d9330d05cb371451a0a4cc590e28d4d616ef6dfa1293fb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page