Skip to main content

tokenwise

Estimate how many tokens a prompt is and what it costs on popular LLMs. Pure Python, no dependencies, no network.

$ echo "Summarize this article in three bullet points." | python -m tokenwise
~12 tokens (46 chars)
  gemini-flash   $0.000001
  ...

Install

pip install tokenwise-py

Or copy tokenwise.py into your project, it has no dependencies.

Usage

python -m tokenwise prompt.txt --out 500      # include expected output tokens
python -m tokenwise prompt.txt --json
from tokenwise import estimate_tokens, cost
n = estimate_tokens(text)
cost(n, 500, "claude-sonnet")

Accuracy

It is a heuristic (chars/4 and word-piece blend, denser for non-Latin scripts like Arabic). Expect roughly 15% error against real tokenizers. Good for budgeting, not billing. Prices live in the PRICES dict at the top of tokenwise.py; update them to match current provider pricing.

Test

python -m pytest

MIT licensed.

Metadata

Release files for tokenwise-py 0.1.0

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

Source distribution (sdist)

Source distribution for tokenwise-py 0.1.0
File Size Uploaded Provenance Actions
tokenwise_py-0.1.0.tar.gz 3.5 kB With provenance Details for tokenwise_py-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tokenwise-py 0.1.0
File Interpreter ABI Platform Actions
tokenwise_py-0.1.0-py3-none-any.whl Python 3 none any Details for tokenwise_py-0.1.0-py3-none-any.whl

Total release size: 7.6 kB

Release files / tokenwise_py-0.1.0.tar.gz

Download URL tokenwise_py-0.1.0.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
be56129d493524fe31982a84147431fbb3f361853e8af5b1fce89b79332b3f4c
BLAKE2b-256 checksum
How to use checksums
3f82238d9544d12bd7a452b4157287b7511eb7b0ee60f8d1d1ce928eee4dea02
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 28, 2026.

Transparency log

Release files / tokenwise_py-0.1.0-py3-none-any.whl

Download URL tokenwise_py-0.1.0-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f2569595f29001daac68464befcce1cb51dcc7dd4345b64c87f0272a2d05f1b6
BLAKE2b-256 checksum
How to use checksums
dbb8cf123018fa9371df94740e354e46838fe8af12517904fa40dc124c3f909d
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 28, 2026.

Transparency log

Security for tokenwise-py 0.1.0

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tokenwise_py-0.1.0.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 28, 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.0 This release

2 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