Skip to main content

Nemesis Shield — Sentinel SDK for Python (web/API/LLM behavioral protection). Learn your app's normal behavior, then block off-baseline requests in enforce mode. ASGI/WSGI/Django middleware + OpenAI/Anthropic/LangChain LLM guards.

Project description

nemesis-shield — Python SDK

Native Python SDK for Nemesis Shield. Computes a privacy-preserving request sketch locally, learns your app's normal behavior, and — in enforce modeblocks off-baseline requests (auth bypass, path traversal, scanners, unusual methods) before your views ever run. Positive-security: this app only ever behaves in these ways. Zero dependencies (stdlib only). Fail-open: if Nemesis is unreachable, your app is unaffected.

pip install nemesis-shield

One line per framework

FastAPI / Starlette (ASGI)

from nemesis_shield.asgi import SentinelMiddleware
app.add_middleware(SentinelMiddleware, token=os.environ["NEMESIS_TOKEN"])

Flask / any WSGI app

from nemesis_shield.wsgi import SentinelWSGI
app.wsgi_app = SentinelWSGI(app.wsgi_app, token=os.environ["NEMESIS_TOKEN"])

Django — add to settings.py and set NEMESIS_TOKEN in the environment:

MIDDLEWARE = ["nemesis_shield.django.SentinelDjango", *MIDDLEWARE]

Raw / anything — use the client directly:

from nemesis_shield import build_sketch
from nemesis_shield.client import SentinelClient
c = SentinelClient(token=os.environ["NEMESIS_TOKEN"])
c.record(build_sketch(method="GET", path="/orders/42", authenticated=True, status=200))

Docs & links

Want more than the one-liner? Full per-framework code, options, and examples:

Framework Detailed guide & source
FastAPI / Starlette (ASGI) nemesis_shield/asgi.py
Flask / WSGI nemesis_shield/wsgi.py
Django nemesis_shield/django.py
Raw client nemesis_shield/client.py
LLM guard nemesis_shield/llm.py
Runnable examples python/tests

How enforcement works

  1. Learn — deploy in observe mode (default). Every request is recorded as a privacy-preserving request signature (method + route + params + auth — never bodies or secrets). Review and approve the learned behaviors in the console.
  2. Enforce — flip the app to enforce in the console. The SDK polls the compiled allow-list in the background, so no redeploy is needed — the console is the source of truth.
  3. Block — any request whose signature isn't in the approved allow-list (once a baseline exists), is explicitly blocked, or matches global threat intel, gets a 403 blocked_by_nemesis_shield before your app handles it. Everything approved passes untouched.

Verified end-to-end (learn → enforce → attack) on FastAPI, Flask, Django and raw: legitimate traffic passes (200) while auth bypass, BOLA, path traversal and scanner probes are blocked (403) and reported.

LLM protection

from nemesis_shield import analyze_llm
result = analyze_llm(prompt=prompt, system=system, response=response, tools=tools)

MIT © Autogon Inc.

Full coverage & safe-unlock

Mount it first / outermost so every route is inspected (not just API routes — attackers hit any path):

app.add_middleware(SentinelMiddleware, token=os.environ["NEMESIS_TOKEN"])  # ASGI; or wrap wsgi_app outermost

What's inspected (privacy-preserving): method + normalized route + query-param structure (names + kinds, never values) + auth flag + status. An off-baseline route, param structure, method, or auth state is blocked in enforce mode. Path-traversal segments normalize to {traversal}.

Safe-unlock (break-glass): the login/auth path is never blocked, so a still-learning baseline can't lock you out. Defaults: /login /signin /sign-in /auth /oauth /session /wp-login.php /wp-admin. Override:

export NEMESIS_SHIELD_BOOTSTRAP="/login,/admin,/healthz"

Verify coverage — in observe mode, hit a normal route, a param, and a scanner path, then confirm all three appear in the console (Activity / Behaviors):

curl -s "http://localhost:8080/" >/dev/null
curl -s "http://localhost:8080/search?q=shoes" >/dev/null
curl -s "http://localhost:8080/.env" >/dev/null   # shows up as an off-baseline behavior

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

nemesis_shield-0.1.2.tar.gz (49.7 kB view details)

Uploaded Source

Built Distribution

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

nemesis_shield-0.1.2-py3-none-any.whl (45.8 kB view details)

Uploaded Python 3

File details

Details for the file nemesis_shield-0.1.2.tar.gz.

File metadata

  • Download URL: nemesis_shield-0.1.2.tar.gz
  • Upload date:
  • Size: 49.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for nemesis_shield-0.1.2.tar.gz
Algorithm Hash digest
SHA256 df0272cdd4dd0a976db8cdd5c2d540718a2d64d7313d58fe63cbe88129a19621
MD5 cb9399c603b0046c2686fbed6230bc4d
BLAKE2b-256 ec527694ab66a916f3f3931354d7d2359efe7fa05f1e0232f59c86bc7f050edd

See more details on using hashes here.

File details

Details for the file nemesis_shield-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: nemesis_shield-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 45.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for nemesis_shield-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3a5d4d3261cfd4ea6de7d6c9e659c716b62796d1ae7ec10214f3bed59f405d9f
MD5 53728a2873131c972f37878fee439f39
BLAKE2b-256 dcfa58bfd1bebebb41939988a321a75003923dc5876df246259a936f79f3594a

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