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:
ValidateResultwith.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,PactSpecEndpointPactSpecAuth,PactSpecTestSuite,PactSpecExample,PactSpecLinks,PactSpecDelegationBenchmark,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
Metadata
Release files for pactspec 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pactspec-0.1.0.tar.gz | 11.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pactspec-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 23.7 kB
Release files / pactspec-0.1.0.tar.gz
| Download URL | pactspec-0.1.0.tar.gz |
|---|---|
| Size | 11.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c77e12fc4b459e6e4abb6f50fb294488344abd077890b8e9925359d6e7d4632e
|
|
BLAKE2b-256 checksum How to use checksums |
316f51889fe938421273926ca8ab63a3ee0e7124906c83f7e85d02cd0d6c7f05
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Release files / pactspec-0.1.0-py3-none-any.whl
| Download URL | pactspec-0.1.0-py3-none-any.whl |
|---|---|
| Size | 11.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b97c29b26dc9d484953aef0820b5bdeb5cd41755e4f0631dafcdd0249542a1f0
|
|
BLAKE2b-256 checksum How to use checksums |
bbbb66b7f4ee836d9128ef668ec95239bda1e36c48143d03adfb22c0cb91a39d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|