{"id":51026584,"url":"https://github.com/gitstq/contextsqueeze-py","last_synced_at":"2026-06-21T20:02:05.382Z","repository":{"id":363869598,"uuid":"1265327658","full_name":"gitstq/contextsqueeze-py","owner":"gitstq","description":"Lightweight LLM Context Compression \u0026 Intelligent Routing Toolkit - Reduce token usage by 50-80%","archived":false,"fork":false,"pushed_at":"2026-06-10T17:15:48.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-10T19:09:07.204Z","etag":null,"topics":["ai","anthropic","cli","compression","cost-savings","developer-tools","llm","openai","python","token-optimization"],"latest_commit_sha":null,"homepage":null,"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/gitstq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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-10T17:12:28.000Z","updated_at":"2026-06-10T17:16:22.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/gitstq/contextsqueeze-py","commit_stats":null,"previous_names":["gitstq/contextsqueeze-py"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/gitstq/contextsqueeze-py","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitstq%2Fcontextsqueeze-py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitstq%2Fcontextsqueeze-py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitstq%2Fcontextsqueeze-py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitstq%2Fcontextsqueeze-py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gitstq","download_url":"https://codeload.github.com/gitstq/contextsqueeze-py/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gitstq%2Fcontextsqueeze-py/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34623906,"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-21T02:00:05.568Z","response_time":54,"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","anthropic","cli","compression","cost-savings","developer-tools","llm","openai","python","token-optimization"],"created_at":"2026-06-21T20:02:04.835Z","updated_at":"2026-06-21T20:02:05.377Z","avatar_url":"https://github.com/gitstq.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://img.shields.io/badge/ContextSqueeze-LLM%20Compression-blue?style=for-the-badge\" alt=\"ContextSqueeze\"\u003e\n\u003c/p\u003e\n\n\u003ch1 align=\"center\"\u003eContextSqueeze\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cb\u003eLightweight LLM Context Compression \u0026 Intelligent Routing Toolkit\u003c/b\u003e\u003cbr\u003e\n  Reduce token usage by 50-80% while preserving semantic meaning\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://github.com/gitstq/contextsqueeze-py/releases\"\u003e\u003cimg src=\"https://img.shields.io/github/v/release/gitstq/contextsqueeze-py?style=flat-square\" alt=\"Release\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/gitstq/contextsqueeze-py/blob/main/LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/github/license/gitstq/contextsqueeze-py?style=flat-square\" alt=\"License\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://github.com/gitstq/contextsqueeze-py/actions\"\u003e\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/gitstq/contextsqueeze-py/ci.yml?style=flat-square\" alt=\"CI\"\u003e\u003c/a\u003e\n  \u003cimg src=\"https://img.shields.io/badge/Python-3.9%2B-blue?style=flat-square\" alt=\"Python\"\u003e\n\u003c/p\u003e\n\n---\n\n## 🎉 Project Introduction\n\nContextSqueeze is a high-performance, lightweight toolkit designed to intelligently compress LLM prompts and context windows. It automatically detects content types, routes them to optimal compression strategies, and significantly reduces token usage without losing semantic meaning.\n\n**Why ContextSqueeze?**\n- 💰 **Save Money**: Reduce API costs by 50-80%\n- ⚡ **Faster Responses**: Shorter prompts = faster inference\n- 🧠 **Smarter Routing**: Auto-detects content type and applies best strategy\n- 🔒 **Local-First**: All processing happens locally, no data leaves your machine\n- 🛠️ **Developer-Friendly**: Simple CLI and Python API\n\n## ✨ Core Features\n\n| Feature | Description |\n|---------|-------------|\n| **Auto Content Detection** | Automatically identifies code, JSON, logs, markdown, and plain text |\n| **4 Compression Strategies** | Semantic, Code, JSON, and Text summarization |\n| **Token Counting** | Accurate token counting for GPT-4, Claude, and other models |\n| **Cost Estimation** | Real-time API cost calculation before and after compression |\n| **Batch Processing** | Process JSONL files with multiple messages at once |\n| **Rich CLI Output** | Beautiful terminal output with tables and progress indicators |\n| **Message Compression** | Compress entire chat message histories |\n\n## 🚀 Quick Start\n\n### Installation\n\n```bash\npip install contextsqueeze\n```\n\n### CLI Usage\n\n```bash\n# Compress a file\nctxsq compress -f large_prompt.txt --ratio 0.5\n\n# Detect content type\nctxsq detect myfile.py\n\n# List strategies\nctxsq strategies\n\n# Batch process\nctxsq batch messages.jsonl -o compressed.jsonl\n\n# Pipe from stdin\ncat log.txt | ctxsq compress --ratio 0.6\n```\n\n### Python API\n\n```python\nfrom contextsqueeze import ContextCompressor\n\n# Initialize compressor\ncompressor = ContextCompressor(model=\"gpt-4\")\n\n# Compress text (auto-detects content type)\nresult = compressor.compress(\n    text=long_text,\n    target_ratio=0.5\n)\n\nprint(f\"Saved {result.savings_percent}% tokens\")\nprint(f\"Compressed: {result.compressed_text}\")\n\n# Get detailed stats\nstats = compressor.get_stats(result)\nprint(f\"Cost saved: ${stats['cost_saved_usd']}\")\n\n# Compress chat messages\nmessages = [\n    {\"role\": \"user\", \"content\": long_user_message},\n    {\"role\": \"assistant\", \"content\": long_assistant_response},\n]\ncompressed = compressor.compress_messages(messages, target_ratio=0.5)\n```\n\n## 📖 Detailed Usage Guide\n\n### Compression Strategies\n\n| Strategy | Best For | How It Works |\n|----------|----------|--------------|\n| **semantic** | General text, articles | Sentence importance scoring + filler removal |\n| **code** | Source code files | Comment removal + whitespace collapse |\n| **json** | JSON data, API responses | Minification + array truncation |\n| **text** | Long documents, logs | Paragraph-based extractive summarization |\n\n### Content Type Detection\n\nContextSqueeze automatically detects these content types:\n\n- **Code**: Python, JavaScript, TypeScript, Go, Rust, Java, C/C++, and more\n- **JSON**: API responses, configuration files\n- **Markdown**: Documentation, README files\n- **Logs**: Application logs with timestamps\n- **HTML/XML**: Web content\n- **Stack Traces**: Error traces and exceptions\n\n### Advanced Options\n\n```bash\n# Specify strategy manually\nctxsq compress -f data.json --strategy json --ratio 0.7\n\n# Use specific model for token counting\nctxsq --model gpt-4o compress -f prompt.txt\n\n# Higher compression ratio\nctxsq compress -f article.md --ratio 0.8\n```\n\n## 💡 Design Philosophy\n\nContextSqueeze was designed with three principles:\n\n1. **Intelligence over Brute Force**: Instead of blindly truncating, we analyze content structure and preserve meaning\n2. **Zero Dependencies for Core**: The core library has minimal dependencies for easy integration\n3. **Developer Experience First**: Beautiful CLI, clear API, comprehensive tests\n\n### Architecture\n\n```\nInput Text\n    |\n    v\n[ContentRouter] --\u003e Detects ContentType\n    |\n    v\n[Strategy Selector] --\u003e Picks optimal strategy\n    |\n    v\n[Compressor] --\u003e Applies compression\n    |\n    v\n[TokenCounter] --\u003e Calculates savings\n    |\n    v\nCompressionResult\n```\n\n## 📦 Packaging \u0026 Deployment\n\n### Build from Source\n\n```bash\ngit clone https://github.com/gitstq/contextsqueeze-py.git\ncd contextsqueeze-py\npip install -e \".[dev]\"\npytest\n```\n\n### Run Tests\n\n```bash\npytest tests/ -v --cov=contextsqueeze\n```\n\n### Code Quality\n\n```bash\nblack src/ tests/\nruff check src/ tests/\nmypy src/\n```\n\n## 🤝 Contributing\n\nWe welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.\n\n1. Fork the repository\n2. Create your feature branch (`git checkout -b feature/amazing-feature`)\n3. Commit your changes (`git commit -m 'feat: add amazing feature'`)\n4. Push to the branch (`git push origin feature/amazing-feature`)\n5. Open a Pull Request\n\n## 📄 License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n---\n\n\u003cp align=\"center\"\u003e\n  Made with ❤️ for the AI developer community\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgitstq%2Fcontextsqueeze-py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgitstq%2Fcontextsqueeze-py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgitstq%2Fcontextsqueeze-py/lists"}