Skip to main content

Minimal Python contracts for the Weaver Stack (contextweaver, agent-kernel, ChainWeaver)

Project description

weaver_contracts Python Package

Minimal Python contracts for the Weaver Stack.

This package provides dataclasses and type definitions for all Core Weaver contracts. It has no runtime dependencies beyond the Python standard library (Python 3.9+).


Installation

pip install weaver_contracts

For development (includes pytest and jsonschema):

pip install "weaver_contracts[dev]"

Verifying SLSA build provenance

Starting with version 0.3.0, releases ship with a PEP 740 Sigstore-signed SLSA build provenance attestation. Earlier releases (0.2.0 and below) do not carry an attestation. Verify a downloaded wheel before installing in production:

pip install sigstore
pip download "weaver_contracts==<VERSION>" --no-deps -d ./dist
sigstore verify identity \
  --cert-identity-regexp '^https://github.com/dgenio/weaver-spec/' \
  --cert-oidc-issuer 'https://token.actions.githubusercontent.com' \
  ./dist/weaver_contracts-*.whl

See SECURITY.md for the full adopter security guidance.


Usage

from weaver_contracts import (
    SelectableItem,
    ChoiceCard,
    RoutingDecision,
    Capability,
    CapabilityToken,
    PolicyDecision,
    Frame,
    Handle,
    TraceEvent,
)
from weaver_contracts.version import CONTRACT_VERSION, is_compatible
from datetime import datetime, timezone

# Routing
item = SelectableItem(id="search-1", label="Search docs", description="Search documentation")
card = ChoiceCard(id="card-1", items=[item], context_hint="Select a retrieval action")
rd = RoutingDecision(
    id="rd-abc",
    choice_cards=[card],
    timestamp=datetime.now(timezone.utc),
    selected_item_id="search-1",
)

# Authorization
token = CapabilityToken(
    token_id="tok-xyz",
    principal="my-agent",
    scope=["org.myapp.search_docs"],
    issued_at=datetime.now(timezone.utc),
    expires_at=datetime(2099, 1, 1, tzinfo=timezone.utc),
)

# Frame (safe output)
frame = Frame(
    frame_id="frame-001",
    capability_id="org.myapp.search_docs",
    summary="Found 3 documents matching 'query'.",
    created_at=datetime.now(timezone.utc),
    handle_refs=["handle-abc"],  # reference to raw artifact
)

Contract Tiers

Module Contents Stability
weaver_contracts.core Core contracts (all 9 types) Stable within major version
weaver_contracts.extended Optional metadata types May evolve in minor versions
weaver_contracts.version Version constants + is_compatible() Stable

Running Tests

cd contracts/python
pip install -e ".[dev]"
pytest

Schema Alignment

The JSON Schemas in contracts/json/ are the language-agnostic source of truth. The Python types mirror the schemas exactly. If a schema changes, the corresponding Python type and tests should be updated in the same PR.

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

weaver_contracts-0.6.0.tar.gz (28.8 kB view details)

Uploaded Source

Built Distribution

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

weaver_contracts-0.6.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file weaver_contracts-0.6.0.tar.gz.

File metadata

  • Download URL: weaver_contracts-0.6.0.tar.gz
  • Upload date:
  • Size: 28.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for weaver_contracts-0.6.0.tar.gz
Algorithm Hash digest
SHA256 7ec49fc721106b320f793385046583f3f4ad15b27a6212aeec8df7e4165715ca
MD5 f5b6117eb769ae54c69f13e118189cbb
BLAKE2b-256 1a86623d81ccb6750041ca6962f6bd7beb723c1dcb2611bf5b667cd9271597e9

See more details on using hashes here.

Provenance

The following attestation bundles were made for weaver_contracts-0.6.0.tar.gz:

Publisher: publish.yml on dgenio/weaver-spec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file weaver_contracts-0.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for weaver_contracts-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 959f2fd88143982c1b4e7d25711b907a559566e67f02340564f47ba64140eb1a
MD5 976f1931274e8c9c8d94bde66fac9426
BLAKE2b-256 e6d7fd5494c21c7a876aa6485e1ec4b7e44bfeb956b3412fcbc07de241f90f5d

See more details on using hashes here.

Provenance

The following attestation bundles were made for weaver_contracts-0.6.0-py3-none-any.whl:

Publisher: publish.yml on dgenio/weaver-spec

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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