SpendPreflightdocs
SDKs / developer guide

Python guard

Typed, local spending rules for the asynchronous Python x402 client.

Operator-maintained documentation
Live features and staging previews are distinguished. Index coverage is not yet available.

Publication pending

The Python 0.1.0 source, pytest suite and Trusted Publishing workflow are prepared. The PyPI project is not yet published; do not rely on an unrelated package claiming the name. Owner account/2FA, release and attestation checks must finish before an installation command is recommended.

Use the existing client

Attach Guard.before_payment with client.on_before_payment_creation. Local mode needs no service account or model call. Default budgets are $1 per payment, hold above $0.25, daily $25; Base USDC only. The async guard reserves budget before signing; use one guard per event loop/budget. Failed authorizations retain reservations. RemoteOptions defaults to a free-trial HTTP call; paid screening requires an explicitly separate bounded payment client.

python-local.py
"""Shared pure advisory tool implementation; the payment guard still must be attached."""
from __future__ import annotations

import json
from typing import Any

from spendpreflight import Rules, evaluate_local


def check_selected_offer(requirement_json: str, resource_url: str, max_usd: str = "1") -> dict[str, Any]:
    """Local rule check only. No OFAC claim, network call, key or payment."""
    if len(requirement_json.encode("utf-8")) > 65536:
        raise ValueError("Payment option must fit in 64 KiB")
    value = json.loads(requirement_json)
    if not isinstance(value, dict):
        raise ValueError("Provide one selected payment option as a JSON object")
    return evaluate_local(value, resource_url, Rules(max_per_payment_usd=max_usd)).to_dict()
Download tested source

LangChain and CrewAI

The local wrapper in the example evaluates one chosen offer, never invokes a model or wallet, and is not an OFAC screen. The package includes real LangChain StructuredTool and CrewAI BaseTool wrappers tested through their invoke/run interfaces. An agent selecting either tool does not replace payment-path enforcement.