Skip to the documentation
All documentation pages ↓

Python SDK

A standard-library client: send, send_quietly, batches and the doctor.

Install

The SDK is a single package, nexguard, written against the standard library only — an SDK that drags in a dependency tree eventually conflicts with the application it is meant to observe. It needs Python 3.11 or later.

Shell
pip install nexguard

A Node.js client is described on the JavaScript SDK page.

Send an event

Python
import os

from nexguard import Event, EventType, NexGuardClient

client = NexGuardClient(
    api_url="https://securiteagi.com",
    api_key=os.environ["NEXGUARD_API_KEY"],      # ngk_…
    source="portal-web",
    signing_secret=None,  # optional; required once the key enforces signing
)

delivered = client.send_quietly(
    Event(
        event_id="login-8f21",                   # stable: your own record id
        event_type=EventType.LOGIN_SUCCESS,
        source="portal-web",
        subject_id="user-42",                    # subject_type defaults to "user"
        payload={"ip": "203.0.113.7", "device_id": "d-1"},
    )
)

Event fills in occurred_at with the current UTC time and builds the envelope for you, including schema_version. EventType lists the canonical types, so the common case needs no mapping and never lands in quarantine.

send or send_quietly

  • send(event) delivers to POST /api/v1/events and returns the response. It raises NexGuardError on any refusal or transport failure, with .status set when there was an HTTP answer.
  • send_quietly(event) returns True if the event landed and False if NexGuard refused it or could not be reached — it swallows those, because a security integration must never be the reason a checkout or a sign-in stops working.
  • A forbidden payload is never swallowed. Both raise ForbiddenField before sending if a payload key contains a password, secret, token, card or bank number, national identifier or document image. That is a bug in the integration, and it should surface while you build it, not as silence in production.

Batches

send_batch(events) splits any number of events into chunks of 100 and posts each to POST /api/v1/events/batch, returning one response per chunk. It raises like send.

Python
from nexguard import NexGuardError

try:
    results = client.send_batch(events)   # any iterable of Event
except NexGuardError as error:
    # error.status is the HTTP status, or None if NexGuard was unreachable.
    # Chunks before the failing one were already delivered; resending them
    # is safe because sending is idempotent on event_id.
    ...

What it refuses to do

  • Send forbidden material — see above. Refusing on your side keeps the material from crossing the network at all.
  • Put a key on the wire in clear. An http:// URL to anything but a local address is refused when the client is constructed, before a credential can be sent.

With signing_secret set, every request carries X-Timestamp, X-Nonce and X-Signature as described in Authentication.

JavaScript (Node.js)

The Node.js client has its own page: JavaScript SDK.

The doctor

An integration that is silently wrong — events refused for a clock skew, sent under a revoked key — looks exactly like a quiet night. The doctor checks the things that go wrong quietly, in the order they bite:

Shell
python -m nexguard.doctor \
  --api-url https://securiteagi.com \
  --api-key "$NEXGUARD_API_KEY"
Output
ok    reachable  200, nexguard-api
ok    clock      0s from the platform's clock
ok    send       one diagnostic event accepted
ok    arrival    skipped; no operator token given

The integration is working.
  1. reachable — the API answers at your base URL (it asks /api/v1/system/info, which needs no key).
  2. clock — this host's clock is within a minute of the platform's; a skewed clock is the most common reason a signed delivery is refused.
  3. send — one diagnostic event, a LOGIN_ATTEMPT from source nexguard-doctor with a fresh event_id, is accepted. It is a real event in your organisation.
  4. arrival — optional. With --token and a console operator's session token, it also reports events that were refused and fields that were dropped, by name.

Pass --signing-secret if the key enforces signing. The exit code is 0 when everything passes and 1 otherwise, so it can run in a deployment pipeline.

We use only the cookies needed to sign you in securely and to remember your language and display choices. No analytics, advertising or third-party cookies.

Cookie policy