SignalGate antifraud backend SDK for Python — thin HTTP forwarder to api.signalgate.ai
Project description
signalgate — Python backend SDK
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 (POST /v0/log)
client.webpage_log(event) # first-party web telemetry (POST /v0/webpage-log, signalgate-web tenant)
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
Override the defaults 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
Full counter list:
| Counter | Labels | Incremented when |
|---|---|---|
check_total |
— | check() called |
check_success_total |
— | check() returned a real verdict |
check_failed_open_total |
— | check() returned a synthesized allow |
check_error_total |
type |
check() raised |
log_enqueued_total |
— | log() accepted into queue |
log_sent_total |
— | server acknowledged a log event |
log_http_error_total |
status |
a log retry was triggered |
log_dropped_total |
reason |
queue_full / closed / retry_exhausted |
Development
pip install -e ".[dev]" # install with dev extras
pytest -q # run the test suite
CI runs pytest -q on every push and PR to main via .github/workflows/test.yml (Python 3.12, pip cache keyed on pyproject.toml).
License
Licensed under the Apache License, Version 2.0.
Links
- Homepage: https://signalgate.ai
- Documentation: https://signalgate.ai/docs/python
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file signalgate-0.1.1.tar.gz.
File metadata
- Download URL: signalgate-0.1.1.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6557d737ace4d083278994c823c1024eaab04dd55fab6dfb7702642fca8b258
|
|
| MD5 |
dd3b587218cd8f5cecbc63dcb7a30306
|
|
| BLAKE2b-256 |
57ceff13bec059fedef1cd49b17b2e65ad7dca62ec99f85fdf145e67527c43f5
|
File details
Details for the file signalgate-0.1.1-py3-none-any.whl.
File metadata
- Download URL: signalgate-0.1.1-py3-none-any.whl
- Upload date:
- Size: 15.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1fa16b221bd77aaa6f7c01225f77229639de10fb79f34b5d922e0a2ea9d6b99f
|
|
| MD5 |
f612ded9ccc3f0df25288ff6067d389a
|
|
| BLAKE2b-256 |
85d8cf724dee1322f712bd987978711ae0d8a67dde93d73eebae4093503b9e84
|