Skip to main content

behavior-contracts (Python)

The COMMON "thin core" runtime primitives from runtime-boundary.md, ported to Python from the TypeScript reference implementation (ts/src/*) with identical semantics.

This package contains only the DSL-agnostic primitives that WS1 classified as COMMON. It has zero backend (DynamoDB / graphddb) dependencies — no boto3, no key marshalling, no retry tuning, no hydrate, no bundle format. Those stay in the consumer (graphddb).

Public API

from behavior_contracts import (
    validate_envelope,     # spec-version fail-closed check
    evaluate_expression,   # expression-ir.md evaluator (i64-checked, truncated %, code-point cmp)
    render_template,        # {param} rendering (strict, Python str() parity)
    run_plan, final_tree,   # execution-plan skeleton (stage / Skip propagation / Policy Kind)
    canonical_value,        # key identity (top-level key sort)
    canonical_json,         # fingerprint (recursive key sort)
    py_float_repr,          # CPython repr(float) canonical decimal
    assert_portable,        # Portability Guard
    decode_value, deep_equals,  # conformance runner adapter (int/float type distinction)
    encode_value, resolve_partial, cmp_code_points,
    SPEC_VERSIONS, ENVELOPE_SPEC_VERSION,
)

Each COMMON primitive raises a typed *Failure exception carrying a .code string matching the conformance protocol's failure-code set.

§8 cross-language traps this port handles

  • % sign: normative mod is truncated (dividend sign). Python's native % returns the divisor sign, so evaluate_expression({"mod":[-7,2]}) == -1 (native -7 % 2 == 1). Implemented via truncated-quotient correction; float mod via math.fmod.
  • int is checked i64: Python int is arbitrary-precision, so i64 bounds are enforced manually; overflow → INT_OVERFLOW.
  • string comparison: code-point order. Python str compares by code point already (no UTF-16 surrogate hazard) — verified in tests.
  • NaN/Inf → Failure; div always float with |int| > 2^53 widening → PRECISION_LOSS; py_float_repr matches CPython repr(float) byte-for-byte (parametrized parity tests).
  • bool is not int: isinstance(x, bool) is checked before int everywhere (Python's bool <: int).

Conformance

Runs the 8 shared suites from ../conformance/vectors/*.json through this package per ../conformance/PROTOCOL.md, including the pre-flight version fail-closed sweep.

python -m behavior_contracts.conformance      # prints its tally; exits non-zero on any failure
# or the console script:
behavior-contracts-conformance

Override the vectors location with DSL_CONTRACTS_VECTORS=/path/to/vectors.

Tests

pip install -e ".[test]"
python -m pytest        # unit tests over the public API + the conformance runner as a test

Docker integration: N/A

This package has no external service dependency (no database, no network) — it is pure in-process logic over JSON-shaped values. There is therefore nothing for a docker-compose integration harness to stand up; the conformance runner and pytest exercise the full surface in-process. (The graphddb adapter PoC in WS4 Part B is where docker-backed integration applies, because graphddb talks to DynamoDB Local.)

Metadata

Release files for behavior-contracts 0.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for behavior-contracts 0.12.0
File Size Uploaded Provenance Actions
behavior_contracts-0.12.0.tar.gz 82.5 kB Without provenance Details for behavior_contracts-0.12.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for behavior-contracts 0.12.0
File Interpreter ABI Platform Actions
behavior_contracts-0.12.0-py3-none-any.whl Python 3 none any Details for behavior_contracts-0.12.0-py3-none-any.whl

Total release size: 151.1 kB

Release files / behavior_contracts-0.12.0.tar.gz

Download URL behavior_contracts-0.12.0.tar.gz
Size 82.5 kB
Tags Source
SHA-256 checksum
How to use checksums
8cec137025ad16fc0598d5a6e906fe14dec48a98c3103a65dcb8eb7c50a5b49c
BLAKE2b-256 checksum
How to use checksums
9674c59ad5a4ba55f4cbab29415d955f470fb588ed86ee1df4b03a11d20983d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Release files / behavior_contracts-0.12.0-py3-none-any.whl

Download URL behavior_contracts-0.12.0-py3-none-any.whl
Size 68.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
601228d007332bc3f0f492ce0bdb4258ab64da709d615c423928069d2c7feef5
BLAKE2b-256 checksum
How to use checksums
d56efeed94db7f10fdf7f2e0a4555371e27c01cd0c3f2d8a5dabcad4a1909c94
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.16

Security for behavior-contracts 0.12.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.12.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page