Skip to main content

SignalGate antifraud backend SDK for Python — thin HTTP forwarder to api.signalgate.ai

Project description

signalgate — Python backend SDK

Python 3.10+ License: Apache 2.0

Thin HTTP forwarder for SignalGate antifraud. Tenants embed this in their backend to call /v0/check (synchronous verdict) and /v0/log (async analytics). The SDK does no crypto — the opaque encrypted payload comes from @signalgate/frontend-js-sdk.

Install

pip install signalgate

For local development against an unpublished checkout:

pip install -e /path/to/backend-python-sdk

Quickstart

from signalgate import Client, Event, EncryptedPayload

client = Client(api_key="<your-jwt>")

event = Event(
    user_id="u_123",
    ip=request.headers.get("X-Forwarded-For", request.remote_addr),
    method="login",
    timestamp="2026-04-01T13:08:50+00:00",
    payload=EncryptedPayload(**frontend_payload_dict),  # verbatim from the browser
    custom={"plan": "pro"},
)

verdict = client.check(event)
if verdict.action == "block":
    raise PermissionError("blocked by SignalGate")

client.log(event)  # fire-and-forget analytics

At process shutdown:

client.close()  # drains the log queue within 5 × log_timeout_ms

Or use it as a context manager:

with Client(api_key="...") as client:
    client.check(event)

Configuration

All defaults match the spec. Override selectively:

Client(
    api_key="...",
    check_timeout_ms=3000,
    log_timeout_ms=1000,
    log_queue_capacity=10000,
    log_max_retries=3,
    fail_open=True,   # default: on timeout/5xx, check() returns allow
)

Error handling

check() raises on 4xx (tenant bug — bad JWT, malformed event). With fail_open=True (default), timeouts / network errors / 5xx return a synthesized CheckResult(action="allow", failed_open=True).

from signalgate import ServerError, TimeoutError, NetworkError

try:
    result = client.check(event)
except ServerError as e:
    # e.status_code, e.code, e.message, e.request_id, e.details
    ...

log() never raises. Failures are counted in client.metrics.

Metrics

client.metrics.get("check_total")
client.metrics.get("check_failed_open_total")
client.metrics.get("log_dropped_total", reason="queue_full")
client.metrics.snapshot()  # all counters

See the spec §7 for the full counter list.

License

Licensed under the Apache License, Version 2.0.

Links

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

signalgate-0.1.0.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

signalgate-0.1.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for signalgate-0.1.0.tar.gz
Algorithm Hash digest
SHA256 70f9c1eb7344bea49d746879be374d1993f4ac86684ab87eaf9af59c6afe4a0f
MD5 c5e208813e91945dcca4c8f0ae25dd7f
BLAKE2b-256 47c4e4013303948ea2e0fe78ef941334c9132fd83e5e23d188b0e24d2d9cdf02

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for signalgate-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 29ccbbd7a7c68cd9da0ab78d22da1106c55428fbf61c271e707b16824c8e07a2
MD5 c66f929058cfe67ace1963d8f6bb0f8b
BLAKE2b-256 bf261105452e64dadcde1b8813a541ba90731c5a17fd652732d03654f933dc96

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