Metadata-Version: 2.4
Name: tokenc
Version: 1.0.0
Summary: Python SDK for The Token Company API - Compress LLM inputs to reduce costs
Home-page: https://github.com/yourusername/tokenc
Author: The Token Company
Author-email: The Token Company <support@thetokencompany.com>
License: MIT
Project-URL: Homepage, https://thetokencompany.com
Project-URL: Documentation, https://thetokencompany.com/docs
Project-URL: Repository, https://github.com/yourusername/tokenc
Project-URL: Bug Tracker, https://github.com/yourusername/tokenc/issues
Keywords: llm,compression,tokens,ai,api,cost-optimization
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.25.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=3.0.0; extra == "dev"
Requires-Dist: black>=22.0.0; extra == "dev"
Requires-Dist: mypy>=0.950; extra == "dev"
Requires-Dist: flake8>=4.0.0; extra == "dev"
Dynamic: author
Dynamic: home-page
Dynamic: license-file
Dynamic: requires-python

# tokenc - Python SDK

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

## Install

```bash
pip install tokenc
```

## Usage

```python
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:

```python
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

```python
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

```python
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}")
```

## Links

- Get API keys: https://thetokencompany.com
- Issues: https://github.com/TheTokenCompany/tokenc-python-sdk/issues
