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.
Install
pip install didis-py
Runnable MCP examples
Start with DID.is MCP examples for three separate jobs:
- Connect your MCP client to DID.is — an opt-in round trip to the existing read-only server; connecting it does not protect your other tools.
- Inspect a public MCP server — offline evidence first, then an explicit live inspection of a server you own or have permission to inspect.
- Block calls after approved definitions change — an offline TypeScript execution boundary using the public SDK fingerprint helpers, not delegation authorization or the full SDK guard.
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.6 migration (breaking): 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.6 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
definitionSha256DID.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,GUARD_UNAVAILABLE,GUARD_MISCONFIGURED. - One tool only:
@didis_guard(client, agent, "github_create_issue", root, capability="github:create_issue", pin=..., definition=...). WithAsyncDidisClientuseAsyncDidisGuard(ordidis_guard, which picks it automatically) onasync deffunctions. on_decisionandDidisGuardError.detailinclude bothtoolandcapability.attest_mcp_pins(client, endpoint, pins)asks DID.is to inspect a public MCP server and compares its hashes with your pins. 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.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| didis_py-0.2.6.tar.gz | 41.6 kB | With provenance | Details for didis_py-0.2.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| didis_py-0.2.6-py3-none-any.whl | Python 3 | none | any | Details for didis_py-0.2.6-py3-none-any.whl |
Total release size: 65.0 kB
Release files / didis_py-0.2.6.tar.gz
| Download URL | didis_py-0.2.6.tar.gz |
|---|---|
| Size | 41.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
24d1124fe3eb4472091929e929ee9b556026098021d5595385c162fba45793eb
|
|
BLAKE2b-256 checksum How to use checksums |
d5775707ab27948d3c95e6bf9a6ea9f070378dc7d0625295957b34f9a3959391
|
| 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 3, 2026.
Transparency logRelease files / didis_py-0.2.6-py3-none-any.whl
| Download URL | didis_py-0.2.6-py3-none-any.whl |
|---|---|
| Size | 23.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
010e14843d108ce7c145f90ae0d86f861f8c727489504169f1bec6a4f7757d96
|
|
BLAKE2b-256 checksum How to use checksums |
97853d022b9441b331c9c6ee7d8ca82e277936697001f2e033a6e112f9069d09
|
| 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 3, 2026.
Transparency logSecurity for didis-py 0.2.6
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.
Attestation for didis_py-0.2.6.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 3, 2026.
Transparency logA 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.