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 live token compression flow meters.

Method A: Single CLI Command

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

This launches the backend API on http://127.0.0.1:8642 and opens the browser interface.

Method B: Development Server (Frontend + Backend)

  1. Start the FastAPI backend server:
    python -m backend
    
  2. In a separate terminal, start the Next.js frontend dev server:
    cd frontend
    npm install
    npm run dev
    
  3. Open http://localhost:3000 in your web browser.

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 a folder or file to Markdown
tmd convert input/ -o output/

# 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 checks:

uv pip install -e ".[dev]"
pytest
ruff check .
mypy src

Testing PyPI Releases in Isolated Docker Sandbox

To test installed PyPI releases in an ephemeral, 100% isolated environment using pipx via Docker:

# 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

Exiting the shell (exit) automatically destroys the container and leaves zero footprint on your system.

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.5.tar.gz (891.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.5-py3-none-any.whl (87.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for tokens_md-0.0.5.tar.gz
Algorithm Hash digest
SHA256 523985ee6320952a2f2a338e86f328c521ccf6342eefb5d3f5c45d36b8b7f44d
MD5 29ad8ec74b1a66b084d49955d8f398c7
BLAKE2b-256 3ea560a89258f030dd1e03e1b4c1eb2e04a4847bc412fd8ae47b6e4cf81d12fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokens_md-0.0.5.tar.gz:

Publisher: release.yml on intelligent-username/tokens.md

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

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

File hashes

Hashes for tokens_md-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 eed277076a44e804b3bb524d736ff85ec18344395b2a269df8f8ea24046c98ee
MD5 f599c2201925a2257936d07f809a8ef6
BLAKE2b-256 80680d77f63299db8b8ac3d17bd7bdf2a90699cf4901e46fa4575e015df70cdf

See more details on using hashes here.

Provenance

The following attestation bundles were made for tokens_md-0.0.5-py3-none-any.whl:

Publisher: release.yml on intelligent-username/tokens.md

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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