Skip to main content

khshield 🛡️

C++23 Python Support Build System License Khwarzma

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

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


License

Distributed under the MIT License. Developed and Maintained by Khwarzma.

Metadata

Release files for khshield 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for khshield 1.0.1
File Size Uploaded
khshield-1.0.1.tar.gz 26.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for khshield 1.0.1
File Interpreter ABI Platform
khshield-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 58.1 kB

Release files / khshield-1.0.1.tar.gz

Download URL khshield-1.0.1.tar.gz
Size 26.9 kB
Tags Source
SHA-256 checksum
How to use checksums
14362455b555ce959a0bf3548bcc68b0bf3b60ea337758ac4785e56d87bfe0eb
BLAKE2b-256 checksum
How to use checksums
843d6f5c279863cf4f126362a199c33fb80981e93a45e3a60e2b366e46c6a88d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release files / khshield-1.0.1-py3-none-any.whl

Download URL khshield-1.0.1-py3-none-any.whl
Size 31.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6c0979ac839bc7fa56c98c8ba62dceac1c577a197bce17a380f3501248949336
BLAKE2b-256 checksum
How to use checksums
32e6e62bdc7a1e9fa91248ad407c0fcf0bd5ba2f34f32f6f72401e4b299906a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

1.0.2

1 release file

This release

1.0.1 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page