Metadata-Version: 2.4
Name: tokenmesh
Version: 0.2.1
Summary: A semantic token optimizer for LLM prompts — reduce tokens, preserve meaning
Author-email: Ankit Singh <your-email@example.com>
License: MIT License
        
        Copyright (c) 2025 TokenMesh Contributors
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/ankitsingh36/tokenmesh
Project-URL: Repository, https://github.com/ankitsingh36/tokenmesh
Project-URL: Issues, https://github.com/ankitsingh36/tokenmesh/issues
Project-URL: Documentation, https://github.com/ankitsingh36/tokenmesh#readme
Keywords: llm,token,optimization,claude,anthropic,nlp,semantic
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: anthropic>=0.25.0
Requires-Dist: sentence-transformers>=2.7.0
Requires-Dist: numpy>=1.24.0
Requires-Dist: tiktoken>=0.7.0
Provides-Extra: faiss
Requires-Dist: faiss-cpu>=1.8.0; extra == "faiss"
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
Requires-Dist: ruff>=0.4; extra == "dev"
Requires-Dist: mypy>=1.9; extra == "dev"
Provides-Extra: all
Requires-Dist: faiss-cpu>=1.8.0; extra == "all"
Dynamic: license-file

# 🧵 TokenMesh

**Why send 8000 tokens when 3000 do the same job?**

[GitHub](https://github.com/AnkitSingh36/tokenmesh) · [Live Demo](https://ankitsingh36.github.io/tokenmesh/demo.html) 

---

## What is this?

TokenMesh is a Python library that **optimizes LLM prompts before sending them to APIs**.

It removes:

* duplicate instructions
* repeated content
* filler text

while **preserving meaning, constraints, and rules**.

---

## Why use it?

LLM prompts are often verbose and redundant, which:

* increases token cost
* slows responses
* hits context limits

TokenMesh helps you:

* reduce **40–75% tokens**
* lower API costs
* keep prompts clean and efficient

Same meaning → fewer tokens → better performance.

---

## Install

```bash
pip install tokenmesh
```

* Python 3.9+
* Works on Windows, Mac, Linux

---

## Quick Start

```python
from tokenmesh import TokenMesh

tm = TokenMesh()

result = tm.optimize(
    text=your_prompt,
    query="optional"
)

print(result.optimized_text)
print(result.reduction_percent)
```

---

## Claude Integration

```python
from tokenmesh.integrations.claude import TokenMeshClaude

client = TokenMeshClaude()

response = client.chat(
    system=long_prompt,
    user="your question",
    model="claude-sonnet-4"
)

print(response.content)
```

---

## Modes

**Lite (safe)**

* 20–40% reduction
* preserves strict rules

```python
from tokenmesh import TokenMeshLite
result = TokenMeshLite().optimize(text)
```

**Aggressive (max compression)**

* 55–75% reduction
* best for long content

```python
from tokenmesh import TokenMeshAggressive
result = TokenMeshAggressive().optimize(text, query="...")
```

---

## Example

Before: ~684 tokens
After: ~290 tokens

Same instructions. ~57% fewer tokens.

---

## License

MIT
