Metadata-Version: 2.4
Name: sift-core
Version: 1.0.0
Summary: Lightweight prompt context minification engine wrapper for SiftPrompt.
Author-email: SiftPrompt Core Team <sift@siftprompt.com>
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.9
Requires-Dist: requests>=2.28.0
Description-Content-Type: text/markdown

# sift-core

> **SiftPrompt Python SDK:** The ultra-lightweight prompt optimization matrix compiler. Strip syntactic noise, conversational fluff, and redundancy from your LLM prompts to save up to 40%+ on your token bills without sacrificing semantic accuracy.

[![PyPI Version](https://img.shields.io/pypi/v/sift-core.svg)](https://pypi.org/project/sift-core)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Python Versions](https://img.shields.io/pypi/pyversions/sift-core.svg)](https://pypi.org/project/sift-core)

---

# Features

- **Intelligent Compression:** Automatically targets conversational filler, over-engineered phrasing, and corporate boilerplate.
- **Fail-Safe Circuit Breaker:** Zero-dependency, defensive engineering. If your network or the gateway drops, the SDK automatically fails open under 50ms, returning your raw prompt so your application never crashes.
- **Multi-Mode Support:** Choose between `balanced`, `aggressive`, and `exact` optimization matrices.
- **Deterministic Local Guardrails:** Instantly catches empty strings or dead whitespace locally without wasting API network credits.

---

# Installation

Install the official package from PyPI using pip:

```bash
pip install sift-core
```

## Configuration
We recommend using `.env.local` files to manage your API keys.

1. Install the helper: `pip install python-dotenv`
2. Create a `.env.local` file in your root:
   ```text
   SIFT_RAPIDAPI_KEY=your_key_here
   ```

---

# Quick Start

### Python

```python
import os
from sift_core import SiftCompiler

# Initialize the compiler with your RapidAPI key
sift = SiftCompiler(api_key="YOUR_SIFT_RAPIDAPI_KEY")

# A conversational prompt heavy with fluff
verbose_prompt = (
    "Hey there AI, I hope you are having an absolutely wonderful day today! "
    "I am working on a small personal project and I was really wondering if you could "
    "do me a huge favor. Can you please act as a world-class, expert senior copywriter "
    "for me right now? Please look over the text very carefully. Thank you so much!"
)

# Execute the compression pass
result = sift.minify(verbose_prompt, mode="aggressive")

print(f"Optimization Rate: {result.metrics['percentage_saved']}% tokens saved")
print("--------------------------------------------------")
print(f"Minified Output:\n\"{result.optimized_text}\"")
```

---

# Optimization Profiles

| Profile | Behavior | Ideal Target |
|---|---|---|
| `balanced` | Standard pruning | Multi-turn conversational contexts |
| `aggressive` | High-density stripping | Verbose corporate boilerplate, pleasantries, and fluff |
| `exact` | Literal matching | Structured code blocks, JSON schemas, structural variables |

---

# Enterprise Resilience (Fail-Open)

This SDK is engineered defensively for mission-critical pipelines, data science workflows, and autonomous AI agents.

It encapsulates network dispatches inside short-circuit timeouts.

If the underlying API layer undergoes throttling (`429`), structural validation denials (`403`), or total network blackouts, the wrapper catches the anomaly cleanly and returns your original uncompressed text sequence seamlessly with an explicit:

```json
{
  "percentage_saved": 0
}
```

metric payload.

Your application's core LLM loop will never crash.