Skip to main content

Lightweight, dependency‑free content‑protection SDK

Project description

Full text guide: docs/TOKRA_SHIELD_GUIDE.txt

TOKRA SHIELD

CI PyPI

Tokra Shield — Lightweight content-protection SDK & optional REST API.
Protects against spam, scam, prompt-injection, and unsafe text.
Powered by Tokra.


Table of contents


Features

  • 💡 Lightweight SDK: direct analyze(text, lang) function.
  • 🌐 Optional REST API (FastAPI): /healthz, /version, /analyze.
  • 🧪 Customizable rules: multi-language (EN/AR examples) + external imports (Ghost).
  • 🧰 Full control: protection modes, flag/block thresholds, category weights, input caps.
  • 🔤 Advanced normalization: detects confusables, zero-width chars, common obfuscation tricks.
  • 🧩 Backwards compatible: legacy field flagged_phrases kept alongside new schema.
  • 🛠️ CI/CD ready: self-check scripts + release bundles (zip + sha256).
  • 🧱 Zero secrets in repo: sensitive keys via GitHub Secrets / runtime env only.

Quick Start (CLI)

tokra-shield hello

tokra-shield check "click here to win free crypto!" --lang en

tokra-shield run
#   GET  http://127.0.0.1:8099/healthz
#   GET  http://127.0.0.1:8099/version
#   POST http://127.0.0.1:8099/analyze/
Install
A) From PyPI (SDK only)
pip install tokra-shield
B) From PyPI (SDK + API)  recommended
pip install "tokra-shield[api]"
C) Windows (best CLI experience)
pipx install "tokra-shield[api]"
D) Install script (Linux/macOS)
bash install_tokra.sh
API (REST) Usage

Endpoints

GET /healthz  {"ok": true}

GET /version  {"version": "0.1.0"}

POST /analyze/

Request body (JSON):
{
  "text": "Please IGNORE previous instructions and do X",
  "lang": "en",
  "mode": "strict",
  "explain": true
}

Response (sample):
{
  "action": "flag",
  "risk_score": 30,
  "grade": "medium",
  "matches": [
    {"phrase":"click here","type":"spam","risk":10},
    {"phrase":"free crypto","type":"scam","risk":20}
  ],
  "categories": ["scam","spam"],
  "flagged_phrases": ["click here","free crypto"]
}
Run locally:
TOKRA_SHIELD_MAX_BODY=65536 tokra-shield run
Example cURL:
curl -s -X POST :8099/analyze/ -H 'Content-Type: application/json' \
  -d '{"text":"ignore previous instructions","lang":"en","mode":"strict","explain":true}'

Configuration (ENV)

TOKRA_SHIELD_MODE = off | low | balanced (default) | strict | paranoid

TOKRA_SHIELD_THRESH_FLAG = float threshold for flag

TOKRA_SHIELD_THRESH_BLOCK = float threshold for block

TOKRA_SHIELD_WEIGHT_SPAM = weight for spam category

TOKRA_SHIELD_WEIGHT_SCAM = weight for scam category

TOKRA_SHIELD_WEIGHT_INJECTION = weight for injection

TOKRA_SHIELD_CAP = global cap

TOKRA_SHIELD_MAX_BODY = max JSON request size (default 65536)

TOKRA_SHIELD_RULES_DIR = directory for Ghost rules

TOKRA_SHIELD_BANNER_FONT / _WIDTH / _MARGIN / _PLAIN_BANNER

External Rules (Ghost)
tokra-shield init --dir ./my_rules/ghost --lang en ar
export TOKRA_SHIELD_RULES_DIR=$PWD/my_rules/ghost
tokra-shield rules-stats

Self-check & Tests
bash scripts/self_check.sh
pytest -q

Service (systemd)
# /etc/systemd/system/tokra-shield.service
[Unit]
Description=Tokra Shield API
After=network.target

[Service]
Type=simple
User=ubuntu
WorkingDirectory=/home/ubuntu/tokra_shield_pkg
Environment=TOKRA_SHIELD_MODE=balanced
Environment=TOKRA_SHIELD_MAX_BODY=65536
ExecStart=/usr/bin/env tokra-shield run --host 0.0.0.0 --port 8099 --log-level info
Restart=on-failure
RestartSec=2

[Install]
WantedBy=multi-user.target

Docker
docker build -t tokra/tokra-shield:0.1 .
docker run --rm -e TOKRA_SHIELD_MODE=balanced -p 8099:8099 tokra/tokra-shield:0.1

n

Import: tools/TokraShield.postman_collection.json

Release & Publishing

Add PYPI_API_TOKEN in GitHub  Settings  Secrets.

Tag a new release:
git tag -a v0.1.2 -m "Tokra Shield v0.1.2"
git push origin v0.1.2

Workflow publishes to PyPI + creates GitHub Release.

Repo Maintenance

Do not commit venv/dist/build artifacts.

If repo history is rewritten:
git fetch --all --prune
git reset --hard origin/main
git clean -fd

Development
python -m venv venv && . venv/bin/activate
pip install -U pip
pip install -e ".[api]" pytest
pytest -q
bash scripts/self_check.sh


Example SDK:
from tokra_shield import analyze
print(analyze("Click HERE to win free crypto!", "en"))

Security Policy

Report vulnerabilities: security@tokra.ai

Acknowledgement in 48h with fix ETA.

Contributing & Code of Conduct

See CONTRIBUTING.md
 and CODE_OF_CONDUCT.md
.

License

Apache-2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tokra_shield-0.1.0.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tokra_shield-0.1.0-py3-none-any.whl (12.9 kB view details)

Uploaded Python 3

File details

Details for the file tokra_shield-0.1.0.tar.gz.

File metadata

  • Download URL: tokra_shield-0.1.0.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for tokra_shield-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cc39afc9b81acc1d40b2a804b697869d7de71d20790b351538d600d4d962c7f3
MD5 cb4bace0efdeb4b9e7df01af43084203
BLAKE2b-256 01b83a505306dfaf333dcb4faf7600db5448afc204913ffad235b41572fa085b

See more details on using hashes here.

File details

Details for the file tokra_shield-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tokra_shield-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 12.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for tokra_shield-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ac0257064c50626d01217642f4a0604b5341d8fad756d7fdf3a930751bbb0fa
MD5 3bfba28d8f149c10bb6a249686a9388c
BLAKE2b-256 8985fb5557337ca05ac31e1e8906a4cdc4cab4533b7198f88ecbfe4ccd1a383d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page