Skip to main content

veridian-sdk

ASGI middleware for Veridian. It reports each request of your app to the Veridian engine and answers 403 {"error": "blocked"} to any session, IP or user that is on the engine's blocklist. Requests on routes the engine classifies as critical are checked with the engine before they run.

Install

pip install veridian-sdk

Requires Python 3.12 or newer.

Usage

Works with any ASGI app (FastAPI, Starlette). Wrap the app and tell the middleware who the user and the session are:

import os

from fastapi import FastAPI
from veridian_sdk import VeridianMiddleware

app = FastAPI()

app = VeridianMiddleware(
    app,
    token=os.environ["VERIDIAN_TOKEN"],
    base_url=os.environ["VERIDIAN_URL"],
    user_id=lambda request: request.state.user_id if hasattr(request.state, "user_id") else None,
    session_id=lambda request: request.cookies.get("sid"),
    trusted_proxies=0,
)
  • user_id and session_id are callables that take a Starlette Request and return a string or None. They run before the app (to enforce the blocklist) and again after it (the app may have just logged the user in). Requests with no user are not reported.
  • Pass a hash of the session cookie as session_id, never the cookie itself.
  • trusted_proxies is the number of your own proxies in front of the app. With 0 the connection IP is used and X-Forwarded-For is ignored, because any client can write it.
  • exclude_paths (default ("/static",)) lists path prefixes that pass straight through with no event and no blocklist check.
  • routes_poll_interval (default 30.0 seconds) is how often the critical routes are read from the engine.
  • check_timeout (default 12.0 seconds) is how long a critical request waits for the engine's verdict.

Critical routes

The middleware reads GET /v1/routes at startup and every routes_poll_interval seconds, and keeps the routes classified critical (method plus route template, for example POST /payouts/bank-account). Before it passes a request on one of them to your app, it calls POST /v1/check with the same event that will go in the batch (same id) and waits for the verdict:

  • block: answers 403 {"error": "blocked"} and your app is never called.
  • allow: the request continues normally.

The check needs a user and a session: a critical request without them is not checked. The event is still sent in the normal batch; the engine ignores a repeated id. Because the app has not run yet, the pre-check carries status 200 and bytes 0, and the engine keeps the first event it sees for an id.

What is sent

One event per request, sent in the background in batches: id, ts, user_id, session_id, ip, user_agent (first 200 characters), device_id, method, route (the route template, for example /items/{item_id}), status and bytes.

The middleware also sets its own device cookie (vrd_did) in the user's browser.

What is never sent

Request and response bodies, and passwords, are never read into events.

Fail-open

If the engine is slow or down, your app is not delayed or broken: the middleware keeps using the last blocklist and the last critical routes it knew. A check that fails, returns anything but 200, returns an unknown verdict or takes longer than check_timeout lets the request through. If the routes were never loaded, nothing is checked and critical routes are unprotected until the engine answers.

License

MIT. See LICENSE.

Metadata

Release files for veridian-sdk 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for veridian-sdk 0.2.0
File Size Uploaded Provenance
veridian_sdk-0.2.0.tar.gz 7.8 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for veridian-sdk 0.2.0
File Interpreter ABI Platform
veridian_sdk-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.7 kB

Release files / veridian_sdk-0.2.0.tar.gz

Download URL veridian_sdk-0.2.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e9469f4f3f176b8bafce89edf13760c161c277964acb93359de3430e1dac96f8
BLAKE2b-256 checksum
How to use checksums
ab08c87c1181e38b75ec762e4fa5cb448e4a713a64fe6b4c52a5447162ca605a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Release files / veridian_sdk-0.2.0-py3-none-any.whl

Download URL veridian_sdk-0.2.0-py3-none-any.whl
Size 8.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c296df05513076a9f2e9453610333f46795f5f34937d865afa0413ec4f5bc966
BLAKE2b-256 checksum
How to use checksums
47f26eccd5c827d4123fd1e647c24b3ee870c7cacd18bebefe0e3c5b2be68388
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Security for veridian-sdk 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for veridian_sdk-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page