Skip to content

Python Consumer Pattern

This pattern demonstrates how application code can consume a structured verification result without treating every non-error response as success.

The example is intentionally transport-neutral.

from dataclasses import dataclass
from typing import Any, Mapping
SUPPORTED = {"PASS", "FAIL", "INCOMPLETE", "UNKNOWN"}
@dataclass(frozen=True)
class VerificationResult:
status: str
artifact_id: str | None
raw: Mapping[str, Any]
def parse_verification_result(payload: Mapping[str, Any]) -> VerificationResult:
status = payload.get("status")
if status not in SUPPORTED:
status = "UNKNOWN"
return VerificationResult(
status=status,
artifact_id=payload.get("artifact_id"),
raw=payload,
)
def may_accept(result: VerificationResult) -> bool:
return result.status == "PASS"

The consumer:

  • accepts only explicit PASS;
  • preserves the original payload;
  • converts unsupported status values to unresolved UNKNOWN;
  • does not infer success from HTTP success or process completion alone.

Replace the example status vocabulary with the authoritative contract used by your integration.