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.1.tar.gz (49.2 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.1-py3-none-any.whl (45.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for nemesis_shield-0.1.1.tar.gz
Algorithm Hash digest
SHA256 95ad2303fca3bdf383083b06124c6feb8ec5e677ca4519ad3e93ed8737234beb
MD5 5135b56c59626ee504dc0ba6a445db1a
BLAKE2b-256 f38860e7829c940b52c8c81e906f8a33bd21fae507023382b318455920a702c0

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for nemesis_shield-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 06ef71e27c136650d7ac5eae55baeb0d76a53c055f0801ca87787b2e572b483d
MD5 6b33d3dcfb7aab2ef096023e223e186c
BLAKE2b-256 4d5357f4ff0eaf1e4c03257470e5036304736116ca36c4ac56b1ec90a3065448

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