Metadata-Version: 2.4
Name: nlproxy
Version: 0.1.0
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Summary: High-performance prompt compression and LLM proxy SDK by IntelliDeep
Home-Page: https://github.com/intellideep/nlproxy
Author: luiserb
Author-email: B-GUST <augustbenitogroup@gmail.com>
Requires-Python: >=3.8
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM

# nlproxy (Python SDK)

A high-performance, **native Python library** for **semantic prompt compression**, prompt firewalling (jailbreak protection), and secure LLM orchestration. Developed and owned by **IntelliDeep**.

Compiled using **PyO3** and **Maturin** directly from Rust, `nlproxy` offers sub-millisecond execution times and **~1500x higher throughput** than pure Python-based middleware solutions.

[![PyPI Version](https://img.shields.io/pypi/v/nlproxy.svg)](https://pypi.org/project/nlproxy)
[![License: Proprietary / Open Core](https://img.shields.io/badge/License-Proprietary%20%2F%20OpenCore-orange.svg)](#licensing)

---

## 🚀 Key Features

* **PII Shielding & Masking**: Redact sensitive data (IPs, emails, API keys, credentials) before they reach cloud LLMs.
* **Semantic Prompt Compression**: Locally segment and compress long prompts using KMeans semantic clustering on quantized weights.
* **Candle Inference Integration**: Utilizes Hugging Face Candle to run Sentence-Transformers locally and offline with zero network calls.
* **Unified Pipeline Orchestration**: Combine cache checks, local prompt firewalls, prompt compression, LLM generation (Gemini, OpenAI, Claude), and post-LLM validation.

---

## 📦 Installation

Ensure you have Python 3.8+ installed, then run:
```bash
pip install nlproxy
```
Maturin will link the precompiled binary (`.so` on Linux/macOS or `.pyd` on Windows) directly into your virtual environment.

---

## 🐍 Python API Quickstart

### 1. Initialize the Offline Model Engine
Before processing prompts, load your local quantized Sentence-Transformers model weights (e.g. `all-MiniLM-L6-v2`) offline:
```python
import nlproxy

success = nlproxy.init_engine(
    "models/model.onnx",
    "models/config.json",
    "models/tokenizer.json"
)

if success:
    print("IntelliDeep semantic engine successfully loaded offline!")
```

### 2. Shield and Compress Prompts
```python
import nlproxy

# Create the request payload
request = nlproxy.CompressRequest(
    text="The database server is located at 192.168.50.22. Please run checkup.",
    mode="general",
    aggressiveness=0.5
)

# Run the native compression
response = nlproxy.compress_prompt(request)

print("Processed text:", response.processed_text)
# Output: "The database server is located at __PROT_82736284__. Please run checkup."

print("Extracted Placeholders:", response.placeholders)
# { "__PROT_82736284__": "192.168.50.22" }
```

### 3. Unified Async Orchestration Pipeline
```python
import nlproxy

request = nlproxy.CompressUnifiedRequest(
    prompt="Generate status report for 192.168.1.1",
    domain="general",
    aggressiveness=0.0,
    provider="gemini",
    model="gemini-1.5-pro",
    bypass_cache=False,
    check_firewall=True,
    semantic_drift_threshold=0.75
)

try:
    response = nlproxy.run_unified_pipeline(request)
    if response.allowed:
        print("Raw response from LLM:", response.raw_response)
        print("Final response with PII restored:", response.final_response)
        print("Execution overhead:", response.latency_ms, "ms")
    else:
        print("Blocked by Prompt Firewall:", response.violations)
except Exception as e:
    print("Execution failed:", str(e))
```

---

## 🛠️ Architectural Open Core Model

This Python SDK is built on top of **nlproxy-core** using a hybrid commercial model:

* **Open Core (Default)**: Single-threaded limit, artificial 150 ms delay per unified execution. Recommended for local developer evaluation.
* **Enterprise Basic**: Up to 4 high-speed parallel threads, 0 ms artificial delays.
* **Enterprise Unlimited**: Uses all CPU cores, 0 ms artificial overhead.

To upgrade, load a valid license key into your environment variables:
```bash
export NLPROXY_LICENSE_KEY="your_base64_or_jwt_license_key"
```

---

## 🏢 Authors & Attribution

Developed and maintained exclusively by **IntelliDeep Solutions**.

* **B-GUST** (Co-founder / Lead Developer)
* **luiserb** (Co-founder / Architect)

---
© 2026 IntelliDeep Solutions. All rights reserved.

