Metadata-Version: 2.4
Name: grid-safety
Version: 1.0.0
Summary: GRID Safety layer and Cognitive Privacy Shield: real-time safety enforcement, PII detection, masking, and compliance presets (GDPR, HIPAA, PCI-DSS) for AI inference.
Project-URL: Homepage, https://github.com/caraxesthebloodwyrm02/GRID
Project-URL: Repository, https://github.com/caraxesthebloodwyrm02/GRID
Project-URL: Issues, https://github.com/caraxesthebloodwyrm02/GRID/issues
Author-email: Irfan Kabir <irfankabir02@gmail.com>
License: MIT License
        
        Copyright (c) 2025-2026 Irfan Kabir
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: ai-safety,fastapi,gdpr,hipaa,pii-detection,privacy,safety
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Security
Requires-Python: <3.14,>=3.13
Requires-Dist: asyncpg>=0.29.0
Requires-Dist: fastapi>=0.104.0
Requires-Dist: loguru>=0.7.3
Requires-Dist: prometheus-client>=0.19.0
Requires-Dist: pydantic>=2.4.0
Requires-Dist: pyjwt>=2.8.0
Requires-Dist: python-jose[cryptography]>=3.3.0
Requires-Dist: pyyaml>=6.0.0
Requires-Dist: redis>=5.0.0
Requires-Dist: sqlalchemy[asyncio]>=2.0.0
Requires-Dist: structlog>=23.1.0
Requires-Dist: uvicorn[standard]>=0.24.0
Provides-Extra: dev
Requires-Dist: httpx>=0.25.0; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.21.0; extra == 'dev'
Requires-Dist: pytest>=8.3.0; extra == 'dev'
Provides-Extra: publish
Requires-Dist: build>=1.0.0; extra == 'publish'
Requires-Dist: twine>=5.0.0; extra == 'publish'
Description-Content-Type: text/markdown

# grid-safety

GRID Safety layer and **Cognitive Privacy Shield**: real-time safety enforcement, PII detection, masking, and compliance presets (GDPR, HIPAA, PCI-DSS) for AI inference.

## Install

```bash
pip install grid-safety
```

## Minimal usage

### Cognitive Privacy Shield (library)

```python
from safety.privacy import get_privacy_engine, PrivacyPreset, AsyncPIIDetector

# Get engine with a compliance preset
engine = get_privacy_engine(preset=PrivacyPreset.BALANCED)

# Detect PII
detections = await engine.detect("Contact me at user@example.com")

# Process (detect + mask/block/ask)
result = await engine.process("My SSN is 123-45-6789")
print(result.processed_text)  # Masked or blocked per preset
print(result.detections)
```

### Run the Safety API server

```bash
safety-api
```

Runs the FastAPI app (auth, rate limiting, pre-check, Privacy Shield middleware, inference queue). Configure via environment variables:

| Variable | Default | Description |
|----------|---------|-------------|
| `SAFETY_API_HOST` | `0.0.0.0` | Bind host |
| `SAFETY_API_PORT` | `8000` | Bind port |
| `SAFETY_API_RELOAD` | (off) | Set to `1`, `true`, or `yes` to enable reload |

Endpoints include:

- `POST /infer` — Submit inference (enqueued to Redis)
- `POST /privacy/detect` — Detect PII in text
- `POST /privacy/mask` — Mask or block PII
- `POST /privacy/batch` — Batch PII detection/masking (up to 100 texts)
- `GET /health`, `GET /metrics`

Set `SAFETY_DEGRADED_MODE=true` to run without Redis (e.g. for tests).

## Architecture

The Cognitive Privacy Shield is GRID's core safety and privacy API. For pipeline details, integration points, and key files, see:

- [Safety Layer & Cognitive Privacy Shield — Architecture](https://github.com/caraxesthebloodwyrm02/GRID/blob/main/docs/SAFETY_ARCHITECTURE.md) (in the GRID repo)

## License

MIT. See [LICENSE](LICENSE).
