Skip to main content

Necoherence for Python

Project overview | 日本語

This package is the Python implementation of Necoherence, for Python 3.12 or later. It uses only the standard library at run time.

Accepting a semantic profile

The caller passes a versioned semantic profile when decoding declarations and when accepting a generated library. The accepted profile defines the wire format used by validation, encoding and decoding, and execution.

The expected profile reference, the sources, and the trusted bytes are passed as arguments separate from the input bytes.

from necoherence.signature_values import ValueContext
from necoherence.type_signatures import checkLibrary, decode_profile_artifact

def decide(expected, sources, trusted, input_bytes, library, type_id, value):
    profile = decode_profile_artifact(expected, sources, trusted, input_bytes)
    checked = checkLibrary({**library, "profile": profile})
    context = ValueContext({
        "profile": checked.value["profile"], "nodes": checked.value["nodes"],
    })
    return context.validate(type_id, value)

Failures are returned as the following types, one for each cause:

  • WireFailure: the profile's wire value is malformed
  • DeclarationFailure: the profile or the library violates a declaration condition
  • AdmissionFailure: the profile differs from the expected reference or sources
  • MeaningFailure: a type lacks a definition of its meaning
  • ValueFailure: validation rejected the value

Other features

Besides the features listed in the project overview, the package provides the following:

  • Declaration checking: detects errors in declarations of types and operations, such as duplicate identifiers and references to undeclared types or definitions
  • Runtime for generated code: the shared value validation and codec routines that generated Python code calls at run time

The optional HTTP adapter is distributed separately as necoherence-http-adapter. It executes network-effect commands and returns observations to the core ledger.

Tools

The generator, which produces Python types and codecs from declarations of types and operations, is in tools/. Its license is AGPL-3.0-only.

Examples

Examples are in examples/.

Testing and type checking

The following commands run the tests and the type checks:

python3 -m pip install ".[dev]"
python3 -m pytest -q
python3 -m mypy src tests

License

MIT

Metadata

Release files for necoherence 0.2.1

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

Source distribution (sdist)

Source distribution for necoherence 0.2.1
File Size Uploaded Provenance
necoherence-0.2.1.tar.gz 92.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for necoherence 0.2.1
File Interpreter ABI Platform
necoherence-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 156.7 kB

Release files / necoherence-0.2.1.tar.gz

Download URL necoherence-0.2.1.tar.gz
Size 92.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5322c4b989037ba28854b486c72629ac36dab7379cb1c01d0cc0431030203d71
BLAKE2b-256 checksum
How to use checksums
2483acd15d9c69f0be898643de12e7c59d105f04ffccf556c482bde0b2024b0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Release files / necoherence-0.2.1-py3-none-any.whl

Download URL necoherence-0.2.1-py3-none-any.whl
Size 64.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
792fd8dcbaff6fb92cf1e30f0e9eb3e3de406f7acf9cd5c6644122e24bc4ca15
BLAKE2b-256 checksum
How to use checksums
b6562acfd8a595c219107e9aab1e488ca989427e552d109361a7674f63471910
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.13

Security for necoherence 0.2.1

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.

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