Skip to main content

didis-py

Official Python SDK for the DID.is public API: DID resolution with evidence, W3C DID Resolution, verifiable credentials, explicit policies, and MCP/A2A agent trust. Sync and async clients on httpx; Python 3.11+. Responses are plain dicts typed with TypedDict (didis.types), so editors and mypy know their shape.

The distribution is didis-py; the import name is didis.

Current release: 0.2.8. See CHANGELOG.md for saved team policy / organizationLei contracts, guard policy_gate and expected_operator_did, Graph provenance types, and the 0.2.7 root-required guard migration.

Install

pip install didis-py

Runnable MCP examples

Start with DID.is MCP examples for three separate jobs:

Default demos need no DID.is account, API key, or LLM key. The inspection example also has a Python mirror. Host subscriptions and optional live calls are separate. See the actual recorded run and the code boundary.

Usage

from didis import DidisClient, AsyncDidisClient, DidisError

# Defaults to the public API at https://did.is/api; pass base_url when self-hosting.
with DidisClient() as didis:
    r = didis.resolve("did:web:identity.foundation")
    print(r["verdict"]["headline"])
    for d in r["dimensions"]:
        print(d["label"], d["state"])

    # DID Resolution v1 (W3C CR Draft HTTPS binding, unmodified)
    w3c = didis.resolve_w3c("did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK")

    # Live resolution stream (server-sent events)
    for event, data in didis.stream("did:web:identity.foundation"):
        if event == "stage":
            print(data["label"], data["status"])

    # Credentials: VC DM 2.0 / 1.1, Data Integrity (eddsa-jcs-2022, ecdsa-jcs-2019), VC-JOSE/VC-JWT
    credential = {
        "@context": ["https://www.w3.org/ns/credentials/v2"],
        "type": ["VerifiableCredential"],
        "issuer": "did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK",
        "validFrom": "2026-01-01T00:00:00Z",
        "credentialSubject": {"id": "did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLdmQR63zLFKfvUwi3"},
    }
    vc = didis.verify_credential(credential)
    print(vc["status"], vc["headline"])

    # Policies are explicit rules, never scores
    out = didis.evaluate_policy(
        "did:web:example.com",
        {"rules": {"allowedMethods": ["web", "webvh"], "domainBinding": "required"}},
    )
    print(out["evaluation"]["status"])

    # Agents
    mcp = didis.inspect_mcp("https://mcp.example.com/mcp")
    print(mcp["status"], mcp["inventoryHash"], len(mcp["tools"]))
    chain: list[str] = []  # delegation receipt JWS strings, root first
    decision = didis.authorize(chain, "payments.refund", trusted_roots=["did:web:example.com"])
    print(decision["authorization"]["decision"])

    try:
        didis.resolve("did:web:does-not-exist.invalid")
    except DidisError as e:
        print(e.status, e.problem.get("code"), e.problem.get("detail"))


async def main() -> None:
    async with AsyncDidisClient() as didis:
        diff = await didis.diff("did:web:example.com")
        print(diff)

Identifiers are percent-encoded exactly once (quote(did, safe="")). Non-2xx responses raise DidisError with the RFC 9457 problem body.

Rate limits. When the public budget is used up the API answers 429 with Retry-After. The client waits that long and retries (up to 2 times, at most 10 s per wait), so a loop of calls slows down instead of failing. Tune with DidisClient(retry={"max_retries": 3, "max_wait": 5}) or turn it off with retry=False.

Project API key (optional). Every check works without a key. A team that needs more than the anonymous per-IP limit can create a key in the DID.is console (Free plan included) and pass it: DidisClient(api_key=os.environ["DIDIS_API_KEY"]). Then inspect_mcp, inspect_a2a, authorize and verify_delegation use the /v1/customer/* routes and count against the team's monthly allowance; results are identical. Each call sends one fresh Idempotency-Key (retries reuse it, so nothing is billed twice). didis.usage() shows the allowance left. Keep the key server-side; it is never sent to public routes.

Guard agent tools

0.2.7 migration from 0.2.5 (breaking; introduced in the 0.2.6 source release): every execution guard, including standalone check calls and one-line wrappers, requires a nonempty, trimmed trusted root DID from application-owned configuration. Missing/null/empty/whitespace roots fail with GUARD_MISCONFIGURED at construction, before any network call or handler. TypeScript requires root statically; Python retains its Optional annotation but validates it at runtime. Do not obtain the trusted root from model output, a submitted delegation, or an ALLOW response. The configured root is sent to verification and compared with the returned root. Definition pins do not establish issuer authority. Rootless chain/tool verification remains advisory: signature-valid alone is not application authorization. 0.2.5 accepts rootless guards; 0.2.7 rejects them, so this is not a backward-compatible patch.

A guarded tool function runs only when (1) the tool definition the agent received still matches the one you approved and (2) DID.is says the agent's registered delegation grants the tool. Every failure raises DidisGuardError and the function does not run (fail-closed).

import os
from didis import DidisClient, DidisGuard, pin_tool_definitions

didis = DidisClient()
# Once, after reviewing the server's tools/list: store these pins in your config.
pins = pin_tool_definitions(reviewed_tools)

guard = DidisGuard(
    didis,
    agent=os.environ["AGENT_DID"],  # from configuration, never from model output
    root=os.environ["ROOT_DID"],    # require this delegation root
    pins=pins,
    require_pins=True,
)

@guard.tool(
    "github_create_issue",                 # the name in tools/list (pin key)
    definition=lambda: current_tools["github_create_issue"],
    capability="github:create_issue",      # what the delegation must grant
)
def create_issue(title: str, body: str) -> dict:
    return github.create_issue(title, body)

Tool name vs capability. MCP and OpenAI tool names may only contain letters, digits, _, - and ., so a tool cannot be called github:create_issue. DID.is capabilities use : namespaces so that github:* can grant a whole group. Pass both: the tool name is used for the pin and error messages, capability is what DID.is is asked about. Without capability, the tool name is used. A capability must be exact (no *, no empty segments, no spaces); an invalid one raises GUARD_MISCONFIGURED before any network call. Since 0.2.1.

Guarding MCP clients (mcp 2.x), LangChain and the OpenAI Agents SDK: see examples/ and Guard agent tools.

  • The definition check is local (RFC 8785 JCS + SHA-256, the same definitionSha256 DID.is reports) and makes no network call.
  • The delegation check calls verify_tool. An ALLOW is reused for 30 s by default (allow_cache_seconds), never past a parseable delegation expiry. Expired approvals are refused even on first use or with caching disabled. Approval deadlines and pins are rechecked after awaited work and immediately before execution; DENY and errors never fall back to stale approvals. Missing/unparseable expiry retains TTL-only behavior. This is a pre-execution boundary, not caller authentication, replay prevention, resource binding or per-stream reauthorization.
  • Error codes: TOOL_DRIFT, TOOL_DEFINITION_MISSING, TOOL_NOT_AUTHORIZED, POLICY_NOT_SATISFIED, OPERATOR_NOT_VERIFIED, GUARD_UNAVAILABLE, GUARD_MISCONFIGURED.
  • Optional policy_gate ({"policy": ...} or saved {"policy_ref": ...}, plus optional credential and trusted_issuer_certificates) evaluates DID/credential/organization LEI rules before delegation checks and refuses non-PASS results with POLICY_NOT_SATISFIED.
  • One tool only: @didis_guard(client, agent, "github_create_issue", root, capability="github:create_issue", pin=..., definition=...). With AsyncDidisClient use AsyncDidisGuard (or didis_guard, which picks it automatically) on async def functions.
  • on_decision and DidisGuardError.detail include both tool and capability.
  • attest_mcp_pins(client, endpoint, pins, expected_operator_did=...) (and attest_mcp_pins_async) asks DID.is to inspect a public MCP server, compares its hashes with your pins, and optionally requires bidirectional operatorBinding (VERIFIED) for expected_operator_did. Run it at startup or deploy time, not per call: it is an outbound, rate-limited request, and servers that need login or run on a private network cannot be inspected.

Webhooks

Console project monitor events use verify_customer_monitor_signature:

from didis import verify_customer_monitor_signature

ok = verify_customer_monitor_signature(
    secret,
    raw_body,
    request.headers["X-DIDIS-Signature"],
    tenant_id=tenant_id,
    project_id=project_id,
    event_id=request.headers["X-DIDIS-Event-ID"],
)

For self-hosted admin daemon monitoring deliveries, use verify_webhook_signature:

from didis import verify_webhook_signature

ok = verify_webhook_signature(
    secret,
    request.headers["x-didis-timestamp"],
    raw_body,
    request.headers["x-didis-signature-256"],
)

Public API reference: https://did.is/developers. Monitoring routes need admin_token= and are only available on self-hosted deployments; they are not exposed by the public API.

Tools-only inventory completeness

inventoryHash fingerprints the observed tools, not an assumed entire catalog. Require inventoryComplete is True for whole-inventory acceptance. Optional missing completeness is unknown, not true. inventoryEvidence reports tools-only page/entry/drop counts, remaining pages and reasons; prompts/resources are not inspected. Pin attestation ok checks requested reviewed pins only and can succeed on partial inventory; it does not attest unpinned tools or establish safety. Duplicate ambiguous names cannot satisfy pins.

License

MIT

Metadata

Release files for didis-py 0.2.8

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

Source distribution (sdist)

Source distribution for didis-py 0.2.8
File Size Uploaded Provenance Actions
didis_py-0.2.8.tar.gz 45.6 kB With provenance Details for didis_py-0.2.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for didis-py 0.2.8
File Interpreter ABI Platform Actions
didis_py-0.2.8-py3-none-any.whl Python 3 none any Details for didis_py-0.2.8-py3-none-any.whl

Total release size: 71.7 kB

Release files / didis_py-0.2.8.tar.gz

Download URL didis_py-0.2.8.tar.gz
Size 45.6 kB
Tags Source
SHA-256 checksum
How to use checksums
750cc906031324607f1dbfcd0828287bc85357f77aca486c06a759892618c8d9
BLAKE2b-256 checksum
How to use checksums
09f75a4ac766cd807a05a6c21f1b9443ea5d6661b86f0a036bb849157d7b979e
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 Nov 17, 2026.

Transparency log

Release files / didis_py-0.2.8-py3-none-any.whl

Download URL didis_py-0.2.8-py3-none-any.whl
Size 26.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
21d45df31d70631f332f82f7c190327b536b0524d6f72c7f7b40af85793edb2d
BLAKE2b-256 checksum
How to use checksums
6431f8059f15527d8d0917b0b4460949032da5e85aa076d87b2e36d528340bb6
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 Nov 17, 2026.

Transparency log

Security for didis-py 0.2.8

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for didis_py-0.2.8.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 Nov 17, 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.

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