Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

tokenc - Python SDK

Compress LLM prompts to reduce costs and latency. 100K tokens compressed in ~85ms.

Install

pip install tokenc

Usage

from tokenc import TokenClient

client = TokenClient(api_key="your-api-key")

result = client.compress_input(
    input="Your long prompt here...",
    model="bear-1.2",  # or "bear-1.1", "bear-1", etc.
    aggressiveness=0.5  # 0.1 = light, 0.5 = balanced, 0.9 = aggressive
)

print(result.output)           # compressed text
print(result.tokens_saved)     # tokens removed
print(result.compression_ratio) # e.g. 1.8x

Protected Content

Wrap text in <ttc_safe> tags to exclude it from compression:

result = client.compress_input(
    input="Compress this but <ttc_safe>keep this exactly as is</ttc_safe>.",
    model="bear-1.2",
    aggressiveness=0.7
)

Context Manager

with TokenClient(api_key="your-api-key") as client:
    result = client.compress_input(input="Your text...", model="bear-1.2", aggressiveness=0.5)

Performance

Requests are gzip-compressed and use HTTP keep-alive automatically.

Input Size E2E Latency Throughput
10K tokens 38ms 198K tok/s
100K tokens 85ms 975K tok/s
1M tokens 542ms 1.5M tok/s

Error Handling

from tokenc import TokenClient, AuthenticationError, RateLimitError, APIError

try:
    result = client.compress_input(input="Your text...", model="bear-1.2")
except AuthenticationError:
    print("Invalid API key")
except RateLimitError:
    print("Rate limit exceeded")
except APIError as e:
    print(f"API error: {e}")

Metadata

Release files for tokenc 1.0.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 tokenc 1.0.0
File Size Uploaded Provenance Actions
tokenc-1.0.0.tar.gz 15.7 kB Without provenance Details for tokenc-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tokenc 1.0.0
File Interpreter ABI Platform Actions
tokenc-1.0.0-py3-none-any.whl Python 3 none any Details for tokenc-1.0.0-py3-none-any.whl

Total release size: 22.8 kB

Release files / tokenc-1.0.0.tar.gz

Download URL tokenc-1.0.0.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
06697738afbb6dfdec2e0053b8e7e17a12eb19f7c0ef0c511fd7cc8f618360d9
BLAKE2b-256 checksum
How to use checksums
3b04b1e139f569779f9e92ef11da466f8bb8bd113708222375d781a0d4252553
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release files / tokenc-1.0.0-py3-none-any.whl

Download URL tokenc-1.0.0-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bd43f41a8de4baf19d0d7a4360c395cbf42354c99d932a51de80b9918f0136a1
BLAKE2b-256 checksum
How to use checksums
e728a750e26387228e83c1b250dc66b990ad1d962d4fab4dea3d78e118a96ce5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Security for tokenc 1.0.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

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