Skip to main content

Official Python SDK for PactSpec — validate, publish, and verify AI agent capability specs

Project description

pactspec

Official Python SDK for PactSpec -- validate, publish, and verify AI agent capability specs.

Installation

pip install pactspec

Quick start

Validate a spec offline

from pactspec import validate_spec

spec = {
    "specVersion": "1.0.0",
    "id": "urn:pactspec:acme:summarizer",
    "name": "Summarizer Agent",
    "version": "1.0.0",
    "provider": {"name": "Acme Corp"},
    "endpoint": {"url": "https://api.acme.com/summarize"},
    "skills": [
        {
            "id": "summarize",
            "name": "Summarize Text",
            "description": "Summarizes input text",
            "inputSchema": {"type": "object", "properties": {"text": {"type": "string"}}},
            "outputSchema": {"type": "object", "properties": {"summary": {"type": "string"}}},
        }
    ],
}

result = validate_spec(spec)
if result.valid:
    print("Spec is valid!")
else:
    for err in result.errors:
        print(f"  - {err}")

Publish to the registry

from pactspec import PactSpecClient

client = PactSpecClient(agent_id="my-agent@acme.com")
pub = client.publish(spec)
print(f"Published: {pub.id} (spec_id: {pub.spec_id})")

Verify a skill

verification = client.verify(pub.id, "summarize")
print(f"Status: {verification.status}")
for tr in verification.results:
    status = "PASS" if tr.passed else "FAIL"
    print(f"  [{status}] {tr.test_id} ({tr.duration_ms}ms)")

Search the registry

from pactspec import search

results = search(q="summarize", verified_only=True)
for agent in results.agents:
    print(f"{agent.name} v{agent.version} - {agent.spec_id}")

API reference

validate_spec(spec) -> ValidateResult

Validate a PactSpec document against the v1 JSON schema. Offline, no network calls.

  • Returns: ValidateResult with .valid (bool) and .errors (list of strings).

PactSpecClient

client = PactSpecClient(
    agent_id="my-agent@acme.com",   # default agent ID for publish
    registry="https://pactspec.dev", # registry URL (default)
    publish_token="tok_...",         # optional auth token
    timeout=30,                      # HTTP timeout in seconds
)
Method Description
client.validate(spec) Validate a spec offline
client.publish(spec) Validate + publish to the registry
client.verify(agent_id, skill_id) Trigger a verification run
client.get_agent(agent_id) Fetch an agent by UUID or spec URN
client.search(q=..., verified_only=...) Search the registry

Module-level functions

The same operations are available as standalone functions:

from pactspec import publish, verify, get_agent, search

result = publish(spec, agent_id="my-agent@acme.com")
verification = verify(result.id, "my-skill")
agent = get_agent(result.id)
results = search(q="coding", verified_only=True)

Exceptions

Exception When
PactSpecError Base class for all SDK errors
PactSpecValidationError Spec fails local schema validation
PactSpecAPIError Registry API returns an error
PactSpecNotFoundError Agent not found (404)

All exceptions include .status_code (int or None) and .details (list of strings).

Types

The pactspec.types module provides TypedDict definitions matching the canonical TypeScript types:

  • PactSpec, PactSpecSkill, PactSpecPricing, PactSpecProvider, PactSpecEndpoint
  • PactSpecAuth, PactSpecTestSuite, PactSpecExample, PactSpecLinks, PactSpecDelegation
  • Benchmark, BenchmarkResult

These are useful for type checking with mypy or pyright.

SDK vs CLI

Python SDK CLI (pactspec)
Use when Building Python apps, CI pipelines, programmatic access Quick one-off commands, shell scripts
Install pip install pactspec npm i -g pactspec
Validation validate_spec(spec) pactspec validate spec.json
Publishing client.publish(spec) pactspec publish spec.json
Output Python objects JSON / human-readable text

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pactspec-0.1.0.tar.gz (11.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pactspec-0.1.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file pactspec-0.1.0.tar.gz.

File metadata

  • Download URL: pactspec-0.1.0.tar.gz
  • Upload date:
  • Size: 11.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for pactspec-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c77e12fc4b459e6e4abb6f50fb294488344abd077890b8e9925359d6e7d4632e
MD5 9b40fd32ccca8e22224c932df966c523
BLAKE2b-256 316f51889fe938421273926ca8ab63a3ee0e7124906c83f7e85d02cd0d6c7f05

See more details on using hashes here.

File details

Details for the file pactspec-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pactspec-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for pactspec-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b97c29b26dc9d484953aef0820b5bdeb5cd41755e4f0631dafcdd0249542a1f0
MD5 b20a648fe04fb32cbe2d721b9460872c
BLAKE2b-256 bbbb66b7f4ee836d9128ef668ec95239bda1e36c48143d03adfb22c0cb91a39d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page