Skip to main content

Canonical schemas for MetaSPN-compatible signal processing systems

Project description

metaspn-schemas

Canonical, stdlib-only schema package for MetaSPN-compatible systems.

Install

pip install metaspn-schemas

Development

python -m pip install -e .[dev]
pytest -q
python -m build
python -m twine check dist/*

Design constraints

  • Tiny and dependency-light (stdlib only)
  • Frozen dataclasses for immutable-by-default objects
  • Explicit schema_version on all public objects
  • to_dict() / from_dict() on every schema
  • UTC ISO-8601 datetime serialization
  • Traceability metadata (trace_id, caused_by, provenance)
  • Privacy mode support (to_dict(privacy_mode=True) omits raw blobs)

Example

from datetime import timezone, datetime

from metaspn_schemas import SignalEnvelope
from metaspn_schemas.utils.ids import generate_id

signal = SignalEnvelope(
    signal_id=generate_id("signal"),
    timestamp=datetime.now(timezone.utc),
    source="linkedin.webhook",
    payload_type="SocialPostSeen",
    payload={"post_id": "123", "platform": "linkedin"},
    schema_version="0.8",
)

as_dict = signal.to_dict()
round_trip = SignalEnvelope.from_dict(as_dict)

Public imports

from metaspn_schemas import (
    SignalEnvelope,
    EmissionEnvelope,
    Task,
    Result,
    SocialPostSeen,
    ProfileEnriched,
    ScoresComputed,
    StateMachineConfig,
    GateTransitionAttempt,
    OutcomeWindowEvaluation,
    CalibrationRecord,
    FailureTaxonomyRecord,
    M1ProfileEnrichment,
    M1ScoreCard,
    M1RoutingRecommendation,
    Recommendation,
    DailyDigestEntry,
    DraftMessage,
    ApprovalOverride,
    NoReplyObserved,
    NoReply,
    TokenSignalSeen,
    PromiseRegistered,
    PromiseEvaluated,
    TokenHealthScoreCard,
    TokenOutcomeObserved,
    TokenOutcomeWindow,
    PromisePredictiveAccuracy,
    CreatorBehaviorCorrelation,
    LearningOutcomeWindow,
    FailureLabel,
    GateCalibrationRecommendation,
    PolicyOverrideReview,
    parse_state_machine_config,
    validate_state_machine_config,
)

Contract Surfaces

v0.2.0 adds canonical shared contracts for gate/state-machine coordination:

  • StateMachineConfig + StateTransitionRule for static machine configuration payloads.
  • GateTransitionAttempt for transition snapshot records.
  • OutcomeWindowEvaluation for downstream learning/evaluation windows.
  • CalibrationRecord + FailureTaxonomyRecord for calibration/failure taxonomy telemetry.

Parse/validate hooks exposed at package top-level:

  • parse_state_machine_config(payload) for current + prior minor payload shape normalization.
  • validate_state_machine_config(config_or_payload) returning (is_valid, errors).

Versioning expectations:

  • Additive fields/types are backwards compatible and ship in minor bumps.
  • Renames/type changes are breaking and require major bumps.
  • Each record carries schema_version for replay/backcompat handling.

Ingestion Contracts

v0.3.0 adds M0 ingestion + resolver handoff schemas:

  • RawSocialPostSeenEvent Required: event_id, source, seen_at, raw. Optional: resolver_handoff.
  • NormalizedSocialPostSeenEvent Required: event_id, source, platform, post_id, author_handle, content, seen_at. Optional: post_url, topics, resolver_handoff.
  • IngestionParseErrorEvent Required: error_id, source, occurred_at, error_type, message. Optional: raw_payload, resolver_handoff.
  • ResolverHandoff Required: handoff_id, entity_ref, provenance_source, provenance_step, attached_at. Optional provenance metadata: metadata.

All ingestion timestamps are normalized to UTC on construction and serde output remains deterministic.

M1 Profile/Score/Route Contracts

v0.4.0 adds canonical M1 payloads for profile enrichment, scoring, and routing:

  • M1ProfileEnrichment Required: enrichment_id, entity_id, enriched_at, role, organization, topics, evidence_summary. Optional metadata: metadata.
  • M1ScoreCard Required: score_id, entity_id, computed_at, fit, quality, reply_likelihood, scorer. Optional scorer metadata: scorer_metadata.
  • M1RoutingRecommendation Required: recommendation_id, entity_id, recommended_at, playbook, rationale, priority, suggested_action. Optional metadata: metadata.

All M1 timestamps are normalized to UTC and dict outputs are serialized deterministically.

M2 Recommendation Contracts

v0.5.0 adds canonical recommendation and human-approval artifacts:

  • Recommendation Required: recommendation_id, entity_id, playbook, score, rationale, priority, created_at. Optional metadata: metadata.
  • DailyDigestEntry Required: digest_entry_id, entity_id, rank, action_item, created_at. Optional metadata: metadata.
  • DraftMessage Required: draft_id, entity_id, channel, body, tone, created_at. Optional: subject, constraints, metadata.
  • ApprovalOverride Required: approval_id, draft_id, status, reason, reviewed_at. Optional: edited_subject, edited_body, reviewer, metadata.

All M2 timestamps are normalized to UTC and serialization remains deterministic.

M3 Learning Contracts

v0.6.0 adds canonical learning-loop artifacts:

  • LearningOutcomeWindow Required: window_id, entity_id, attempted_at, window_start, window_end, outcome, success. Optional: metrics.
  • FailureLabel Required: label_id, entity_id, category, code, evidence, labeled_at. Optional: metadata.
  • GateCalibrationRecommendation Required: recommendation_id, gate_name, created_at, threshold_delta, cooldown_seconds_delta, confidence, rationale. Optional: based_on_windows, metadata.
  • PolicyOverrideReview Required: review_id, recommendation_id, decision, reviewed_at, reviewer, reason. Optional: applied_threshold_delta, applied_cooldown_seconds_delta, metadata.

All M3 timestamps are normalized to UTC and list/dict outputs are deterministic.

Demo Contract Subset

v0.7.0 verifies a canonical demo path across stages:

  • Ingestion/social: NormalizedSocialPostSeenEvent
  • Profile/scoring/routing: M1ProfileEnrichment, M1ScoreCard, M1RoutingRecommendation
  • Recommendation artifacts: Recommendation, DailyDigestEntry, DraftMessage
  • Outcomes: NoReplyObserved (synthetic/manual no-reply support), plus existing message/reply outcomes
  • Learning loop: LearningOutcomeWindow, FailureLabel, GateCalibrationRecommendation

Focused demo serde tests ensure this subset runs without ad hoc payload classes.

Token/Promise Contracts

v0.8.0 adds canonical token/promise lifecycle contracts:

  • TokenSignalSeen
  • PromiseRegistered
  • PromiseEvaluated
  • TokenHealthScoreCard
  • TokenOutcomeObserved
  • TokenOutcomeWindow
  • PromisePredictiveAccuracy
  • CreatorBehaviorCorrelation
  • NoReply (explicit alias-style no-reply schema support in addition to NoReplyObserved)

These contracts use deterministic dict serialization and UTC-normalized timestamps.

Package layout

metaspn-schemas/
  pyproject.toml
  README.md
  src/metaspn_schemas/
    __init__.py
    core.py
    tasks.py
    entities.py
    social.py
    outcomes.py
    token_promises.py
    recommendations.py
    learning.py
    features.py
    ingestion.py
    state_machine.py
    state_fragments.py
    utils/
      ids.py
      time.py
      serde.py
  test/
    test_serde.py
    test_ids.py
    test_backcompat.py
    test_ingestion.py
    test_m1_contracts.py
    test_m2_contracts.py
    test_m3_learning_contracts.py
    test_token_promises.py
    test_demo_contracts.py
    test_state_machine.py

Release

Release automation is configured in:

  • .github/workflows/ci.yml
  • .github/workflows/publish.yml

See RELEASE.md for the end-to-end push + PyPI release flow.

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

metaspn_schemas-0.8.0.tar.gz (21.4 kB view details)

Uploaded Source

Built Distribution

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

metaspn_schemas-0.8.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file metaspn_schemas-0.8.0.tar.gz.

File metadata

  • Download URL: metaspn_schemas-0.8.0.tar.gz
  • Upload date:
  • Size: 21.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for metaspn_schemas-0.8.0.tar.gz
Algorithm Hash digest
SHA256 8f60af1f5ae3115dd6d88f56343f5591d4b8bb41a48915eb52a26b274735d4a4
MD5 9c7f54558dd3ca89b4ed8560738ea296
BLAKE2b-256 3e5ad78a0c7f65ecc8c9e9204fc28f05db5f70f19b286523275b1541e577934a

See more details on using hashes here.

Provenance

The following attestation bundles were made for metaspn_schemas-0.8.0.tar.gz:

Publisher: publish.yml on MetaSPN/metaspn-schemas

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

File details

Details for the file metaspn_schemas-0.8.0-py3-none-any.whl.

File metadata

File hashes

Hashes for metaspn_schemas-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ceb268874e6ead450ca89c13593350e6de1af063acaa9aae0597b84390f5065c
MD5 00a69b97d59102387a1125f7c1c90952
BLAKE2b-256 575e4f979055f6b631ad426ac3a5153246c7096e93e9d34b503f647521842705

See more details on using hashes here.

Provenance

The following attestation bundles were made for metaspn_schemas-0.8.0-py3-none-any.whl:

Publisher: publish.yml on MetaSPN/metaspn-schemas

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