Metadata-Version: 2.4
Name: pynonymizer-core
Version: 1.0.0
Summary: Native Zero-Dependency In-Memory Database Anonymizer & GDPR Test Data Generator (CLI & MCP Server)
Author-email: THE HIVE // BSO <diamantenschmiede@proton.me>
Maintainer: tastenkasperle
License: MIT
Project-URL: Homepage, https://github.com/tastenkasperle/pynonymizer_core
Project-URL: Bug Tracker, https://github.com/tastenkasperle/pynonymizer_core/issues
Project-URL: Repository, https://github.com/tastenkasperle/pynonymizer_core.git
Keywords: mcp,mcp-server,database,sqlite,anonymizer,gdpr,dsgvo,test-data,zero-dependency
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Database
Classifier: Topic :: Security
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# 🛡️ Pynonymizer Core

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
[![Security: Raptor Guard V2](https://img.shields.io/badge/Security-Raptor_Guard_V2_Zero--Vuln-emerald.svg)](https://github.com/tastenkasperle/pynonymizer_core)
[![MCP: Stdio Protocol](https://img.shields.io/badge/MCP-JSON--RPC_2.0-orange.svg)](https://modelcontextprotocol.io)
[![Zero Dependencies](https://img.shields.io/badge/Dependencies-0-brightgreen.svg)](https://github.com/tastenkasperle/pynonymizer_core)
[![Compliance: GDPR Art. 32](https://img.shields.io/badge/Compliance-GDPR_Art._32-blue.svg)](https://gdpr-info.eu/art-32-gdpr/)

**Pynonymizer Core** is a native, zero-dependency in-memory SQLite database anonymization engine and GDPR/DSGVO test data generator designed for developers, CI/CD pipelines, and autonomous AI agents.

Freed from brittle host dependencies (`pg_dump`, `mysql` in `$PATH`) and heavy ORM overhead, Pynonymizer Core operates directly via Python's native `sqlite3` runtime—either in-memory or on disk with safe copy-on-write isolation.

---

## 🌟 Key Features

- **Zero External Dependencies:** Built purely on Python's standard library. Instant portability across Windows, Linux, and macOS without binary compilation.
- **Auto Strategy Inference:** Intelligently detects PII columns (names, emails, phone numbers, addresses, salaries, tax IDs) and generates declarative masking strategies.
- **In-Memory & File-Safe Operations:** Execute high-throughput anonymization entirely in RAM or create verified, scrubbed file copies.
- **Model Context Protocol (MCP) Ready:** First-class Stdio JSON-RPC 2.0 interface for Claude Desktop, Cursor, Antigravity, and autonomous agent frameworks.
- **Raptor Guard V2 Certified:** Hardened against SQL injection, column identifier tampering, and path traversal vectors.

---

## 🚀 Quickstart & Installation

Install directly via pip:
```bash
pip install .
```

Or install from distribution:
```bash
pip install pynonymizer-core
```

---

## 💻 CLI Usage

The command-line interface provides lightweight, modular commands for inspection, rule generation, and execution.

### 1. Inspect Database Schema
Inspect tables, columns, data types, and primary keys:
```bash
pynonymizer-core inspect /path/to/database.db
```

### 2. Auto-Generate Anonymization Strategy
Infer column semantics and export an editable strategy JSON file:
```bash
pynonymizer-core generate-strategy /path/to/database.db > strategy.json
```

Example `strategy.json`:
```json
{
  "users": {
    "email": "unique_email",
    "name": "full_name",
    "phone": "phone_number"
  },
  "employees": {
    "salary": "random_int"
  }
}
```

### 3. Execute Anonymization
Anonymize a database file into a sanitized target output:
```bash
pynonymizer-core anonymize /path/to/database.db --strategy strategy.json --output /path/to/anonymized.db
```

---

## 🤖 Model Context Protocol (MCP) Server

Pynonymizer Core includes an embedded Stdio MCP server compliant with JSON-RPC 2.0, giving AI agents direct tools to inspect schemas and sanitize datasets on demand.

### Provided Tools

| Tool Name | Description | Required Arguments |
|---|---|---|
| `db_inspect_schema` | Returns tables, columns, types, and primary keys | `db_path` |
| `db_generate_strategy` | Evaluates schema and generates recommended GDPR masking map | `db_path` |
| `db_anonymize` | Applies declarative strategy to sanitize database | `source_db`, `strategy` (optional: `target_db`) |

### Claude Desktop / Cursor Setup

Add the following snippet to your `claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "pynonymizer-core": {
      "command": "python",
      "args": ["-m", "src.mcp.server"]
    }
  }
}
```

Or using Docker:
```json
{
  "mcpServers": {
    "pynonymizer-core": {
      "command": "docker",
      "args": ["run", "-i", "--rm", "pynonymizer-core"]
    }
  }
}
```

---

## 🧪 Testing & Security Verification

Run the test suite:
```bash
python -m unittest discover -s tests
```

### Security Posture (Raptor Guard V2)
- **Zero Sinks / Leaks:** No outbound socket requests or analytics telemetry.
- **Prepared Statements:** Parameterized queries for deterministic execution.
- **Deterministic Tokenization:** Safe synthetic data replacement conforming to GDPR Art. 32 requirements.

---

## 📄 License

MIT License. Developed and maintained by **THE HIVE // BSO** ([diamantenschmiede](https://github.com/tastenkasperle)).
