Skip to main content

Nilguard Python SDK — server-side error tracking with token-based ingest

Project description

Nilguard — Python SDK

Server-side error tracking for ASGI apps (FastAPI, Starlette). Mirrors the browser SDK's wire format so the dashboard, ticketing and agent-run pipeline work unchanged.

Install

pip install nilguard

For local development, install the package in editable mode from this directory:

uv pip install -e .

You can also pull it directly as a [tool.uv.sources] path entry from another project during local testing.

Quick start

from fastapi import FastAPI
import nilguard

nilguard.init(
    service="billing-api",                     # human-readable identifier
    framework="fastapi",                       # dashboard renders the right icon
    ingest_key="ng_srv_...",                  # shown once at mint time
    backend_url="https://nilguard.example.com",
    environment="production",
    release="2026-05-23-a1b2c3d",
)

app = FastAPI()
app.add_middleware(nilguard.NilguardASGIMiddleware)

@app.get("/healthy")
async def healthy():
    return {"ok": True}

@app.get("/boom")
async def boom():
    1 / 0   # raises ZeroDivisionError; middleware sends a crash bundle, then re-raises

Try the FastAPI example without installing anything

The examples/fastapi_demo.py script uses PEP 723 inline metadata so uv will install FastAPI + uvicorn + this SDK (via a local path source) for you on first run:

cd examples/python-fastapi
NILGUARD_INGEST_KEY="ng_srv_..." uv run fastapi_demo.py

Manual capture

try:
    risky()
except Exception as exc:
    nilguard.capture_exception(exc, context={"job_id": job.id})
    raise

What gets sent

  • Clean requests send nothing. The middleware stays on the request path only long enough to observe exceptions.
  • Crash bundle on unhandled exception. Includes a network event describing the inbound request plus a crash object with signal=server_exception and a redacted traceback in metadata.
  • Headers, cookies, query values, and anything matching the redaction denylist (authorization|cookie|token|secret|password|session|credential|auth) are scrubbed client-side before the POST. The backend re-applies the same rules — it remains the source of truth.

Auth

All ingest requests carry Authorization: Bearer <ingest_key>. No Origin/CORS dance: the token is the only thing the backend trusts for the server-ingest path.

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

nilguard-0.1.1.tar.gz (31.0 kB view details)

Uploaded Source

Built Distribution

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

nilguard-0.1.1-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nilguard-0.1.1.tar.gz
  • Upload date:
  • Size: 31.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nilguard-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e170317ef0797f38affb42ac761103a4112aebaf037d1edc09bc9f363a5f9b00
MD5 fb28b8e6c5f123402395239046f20b5a
BLAKE2b-256 4d2a03336e7bb7e884d6ee4e30995961ae7fe70177420696b3a21d468bff95cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for nilguard-0.1.1.tar.gz:

Publisher: publish-python.yml on amalshaji/nilguard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: nilguard-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 13.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for nilguard-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2b98de7551b0abee335b2b0de53c34d060b6a1861393cb0e3639dd218b199213
MD5 03bfd7d2d71cd89cc1d8cd68e7a6a12d
BLAKE2b-256 bc141888c4c07735ad9925b61665f1615443ec26542babdb17f39a4c7da87465

See more details on using hashes here.

Provenance

The following attestation bundles were made for nilguard-0.1.1-py3-none-any.whl:

Publisher: publish-python.yml on amalshaji/nilguard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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