khshield 🛡️
High-Throughput, Zero-GPU Multimodal Content Moderation Engine in C++23 & Python
khshield is an enterprise-grade content moderation suite engineered for low-latency, real-time evaluation of text, visual buffers, and acoustic streams. Built with a native C++23 core and lightweight Pybind11 bindings, khshield enforces strict content safety policies without heavy GPU dependencies, optimizing infrastructure costs on cloud and edge host nodes.
Technical Highlights
- Multi-Dialect Arabic Text Engine: Integrated Aho-Corasick automaton with dynamic JSON rulesets covering 20+ Arabic country dialects (
EGY,SAU,JOR,PAL,SYR,GULF,MSA, etc.) alongside Arabizi normalization and quantized CPU-bound SAM text inference. - Zero-GPU Visual Processing: Combines adaptive HSV skin contour detection, face bounding-box exclusion zones, and geometric spatial analysis directly on raw NumPy image buffers (
uint8). - Acoustic Energy & Spectral Analysis: Evaluates PCM audio streams (
float32) via Fast Fourier Transform (FFT) spectral energy tracking, Root Mean Square (RMS) envelope calculation, and BPM detection. - Zero-Copy Memory Mapping: Direct C++ buffer access for Python NumPy arrays, avoiding data duplication overhead during image and audio evaluations.
- Deterministic Resource Boundaries: Optimized for low-spec hosts (bounded within 2 vCPUs and minimal RAM footprint) via stream ring-buffering.
Installation
Via PyPI (Recommended)
pip install khshield
Build Native C++ Library from Source
git clone [https://github.com/khwarzma/kh-shield.git](https://github.com/khwarzma/kh-shield.git)
cd kh-shield
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build -j$(nproc)
Quickstart (Python API)
1. Multi-Dialect Text Moderation
import khshield
# Initialize engine with all 20+ Arabic dialects
engine = khshield.ShieldEngine(preset=khshield.Preset.STRICT)
report = engine.analyze_text("نص عشوائي للتحقق من السلامة")
print(f"Is Safe: {report.is_safe}")
# Scope text moderation strictly to specific dialects (e.g., Egyptian & Saudi)
egy_sau_engine = khshield.ShieldEngine(dialects=["EGY", "SAU"])
2. Visual Buffer Analysis (NumPy / OpenCV)
import numpy as np
import khshield
# Raw RGB image array (Height x Width x Channels)
image_buffer = np.zeros((100, 100, 3), dtype=np.uint8)
report = khshield.analyze_image(image_buffer, width=100, height=100, channels=3)
if not report.is_safe:
print(f"Skin Exposure Ratio: {report.visual.skin_percentage:.2f}")
3. Audio Stream Evaluation
import numpy as np
import khshield
# PCM float32 audio samples (44.1kHz)
pcm_data = np.zeros(44100 * 2, dtype=np.float32)
report = khshield.analyze_audio(pcm_data, sample_rate=44100)
print(f"Audio Flagged: {report.audio.flagged} | BPM: {report.audio.bpm}")
Documentation Directory
- ARCHITECTURE.md — Pipeline mechanics, multithreading model, and memory buffers.
- PRESETS_AND_RULES.md — Mathematical formulas, HSV boundaries, and preset configurations.
- API_REFERENCE.md — Complete C++ and Python API specification.
- AI_INSTRUCTIONS.md — Architectural guardrails and coding standards for AI assistants.
License
Distributed under the MIT License. Developed and Maintained by Khwarzma.
Metadata
Release files for khshield 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| khshield-1.0.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.27+ x86-64, Linux glibc 2.28+ x86-64 | Details for khshield-1.0.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
Release files / khshield-1.0.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | khshield-1.0.2-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 259.8 kB |
| Tags | CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
68a5edf2809f14f747ddcdf11eb89ecc89de73d92f1020dd13737eb4d21dd011
|
|
BLAKE2b-256 checksum How to use checksums |
246ae62b16ddb6a2abec1cfe5fd0cc28897f2340a172ebfceb1522529022b916
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for khshield 1.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.