{"id":50597478,"url":"https://github.com/thetokencompany/the-token-company-python","last_synced_at":"2026-06-09T19:00:31.071Z","repository":{"id":362627821,"uuid":"1257724157","full_name":"TheTokenCompany/the-token-company-python","owner":"TheTokenCompany","description":"Python SDK for The Token Company. Compress LLM prompts to reduce costs and latency","archived":false,"fork":false,"pushed_at":"2026-06-05T05:41:56.000Z","size":36,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-08T18:28:14.776Z","etag":null,"topics":["ai","compression","llm","middleware","optimization","pip","python"],"latest_commit_sha":null,"homepage":"https://thetokencompany.com/docs","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TheTokenCompany.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-03T00:32:04.000Z","updated_at":"2026-06-05T05:42:00.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/TheTokenCompany/the-token-company-python","commit_stats":null,"previous_names":["thetokencompany/the-token-company-python"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/TheTokenCompany/the-token-company-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheTokenCompany%2Fthe-token-company-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheTokenCompany%2Fthe-token-company-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheTokenCompany%2Fthe-token-company-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheTokenCompany%2Fthe-token-company-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TheTokenCompany","download_url":"https://codeload.github.com/TheTokenCompany/the-token-company-python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheTokenCompany%2Fthe-token-company-python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34121022,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-09T02:00:06.510Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","compression","llm","middleware","optimization","pip","python"],"created_at":"2026-06-05T15:30:38.705Z","updated_at":"2026-06-09T19:00:30.976Z","avatar_url":"https://github.com/TheTokenCompany.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n# The Token Company Python SDK\n\nCompress LLM prompts to reduce costs and latency. 100K tokens compressed in ~85ms.\n\n[![CI](https://github.com/TheTokenCompany/the-token-company-python/actions/workflows/ci.yml/badge.svg)](https://github.com/TheTokenCompany/the-token-company-python/actions/workflows/ci.yml)\n[![PyPI version](https://img.shields.io/pypi/v/the-token-company)](https://pypi.org/project/the-token-company/)\n[![Python versions](https://img.shields.io/pypi/pyversions/the-token-company)](https://pypi.org/project/the-token-company/)\n[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/TheTokenCompany/the-token-company-python/blob/main/LICENSE)\n\n[Docs](https://thetokencompany.com/docs) · [Website](https://thetokencompany.com) · [Dashboard](https://app.thetokencompany.com) · [Node.js SDK](https://github.com/TheTokenCompany/the-token-company-node)\n\n\u003c/div\u003e\n\n## Install\n\n```bash\npip install the-token-company\n```\n\n## Quick start\n\n```python\nfrom thetokencompany import TheTokenCompany\n\nclient = TheTokenCompany(api_key=\"ttc-...\")\nresult = client.compress(\"Your long prompt text here...\", model=\"bear-2\")\n\nprint(result.output)           # compressed text\nprint(result.tokens_saved)     # tokens removed\nprint(result.compression_ratio)  # e.g. 1.8\n```\n\n## SDK wrappers\n\nDrop-in wrappers that auto-compress all non-assistant messages before sending to your LLM. Assistant messages pass through unchanged so the provider's KV cache stays warm.\n\n### OpenAI / OpenRouter\n\n```python\nfrom openai import OpenAI\nfrom thetokencompany.openai import with_compression\n\nclient = with_compression(OpenAI(), compression_api_key=\"ttc-...\")\n\nresponse = client.chat.completions.create(\n    model=\"gpt-4o\",\n    messages=[\n        {\"role\": \"system\", \"content\": \"You are a helpful assistant...\"},\n        {\"role\": \"user\", \"content\": \"Summarize these results...\"},\n    ],\n)\n```\n\nWorks with `AsyncOpenAI` too — the wrapper detects async automatically.\n\n### Anthropic\n\n```python\nfrom anthropic import Anthropic\nfrom thetokencompany.anthropic import with_compression\n\nclient = with_compression(Anthropic(), compression_api_key=\"ttc-...\")\n\nresponse = client.messages.create(\n    model=\"claude-sonnet-4-6\",\n    max_tokens=1024,\n    system=\"You are a helpful assistant...\",\n    messages=[{\"role\": \"user\", \"content\": \"Summarize these results...\"}],\n)\n```\n\nBoth `messages` and the `system` parameter are compressed.\n\n## Async\n\n```python\nfrom thetokencompany import AsyncTheTokenCompany\n\nasync with AsyncTheTokenCompany(api_key=\"ttc-...\") as client:\n    result = await client.compress(\"Your long prompt text...\")\n```\n\n## Models\n\n| Model      | Description            |\n|------------|------------------------|\n| `bear-2`   | Latest, recommended    |\n| `bear-1.2` | Previous generation    |\n\n## Aggressiveness\n\nControl compression intensity with `aggressiveness` (0.0 – 1.0, default 0.5):\n\n```python\nresult = client.compress(text, model=\"bear-2\", aggressiveness=0.8)\n```\n\n## App ID\n\nTag compression requests with an application identifier for usage tracking:\n\n```python\n# Set on the client — applies to all requests\nclient = TheTokenCompany(api_key=\"ttc-...\", app_id=\"my-chatbot\")\n\n# Or per-request (overrides the client-level value)\nresult = client.compress(text, model=\"bear-2\", app_id=\"my-chatbot\")\n```\n\nAlso supported in wrappers:\n\n```python\nclient = with_compression(OpenAI(), compression_api_key=\"ttc-...\", app_id=\"my-chatbot\")\n```\n\n## Gzip\n\nEnable gzip compression of request payloads for better performance on large inputs (up to 2.2x faster on 1M+ tokens):\n\n```python\nclient = TheTokenCompany(api_key=\"ttc-...\", gzip=True)\n```\n\n## Protect text from compression\n\nUse `protect()` to wrap content in `\u003cttc_safe\u003e` tags — protected text passes through unchanged:\n\n```python\nfrom thetokencompany import protect\n\nprompt = f\"{protect('system:')} You are a helpful assistant.\\n{protect('user:')} Hello!\"\nresult = client.compress(prompt, model=\"bear-2\")\n```\n\n## Response\n\n`CompressResponse` fields:\n\n| Field              | Type    | Description                        |\n|--------------------|---------|------------------------------------|\n| `output`           | `str`   | Compressed text                    |\n| `output_tokens`    | `int`   | Token count after compression      |\n| `input_tokens`     | `int`   | Token count before compression     |\n| `tokens_saved`     | `int`   | Tokens removed                     |\n| `compression_ratio`| `float` | Ratio (e.g. 1.8x)                 |\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthetokencompany%2Fthe-token-company-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthetokencompany%2Fthe-token-company-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthetokencompany%2Fthe-token-company-python/lists"}