Skip to main content

Invariant

A Python-based deterministic execution engine for directed acyclic graphs (DAGs). Invariant treats every operation as a pure function, providing aggressive caching, deduplication, and bit-for-bit reproducibility.

Invariant was motivated by the need for deterministic graphics pipelines: icons, badges, dynamic UI components, and data visualizations where aggressive caching and bit-for-bit reproducibility matter. Critically, layouts can be described without a final size—size is injected at execution time and everything else is derived via the expression language. The engine itself is domain-agnostic; domain implementations like Invariant GFX provide graphics ops and plug in via the op registry.

Features

  • Aggressive Caching: Artifacts are reused across runs if inputs match
  • Deduplication: Identical operations execute only once
  • Reproducibility: Bit-for-bit identical outputs across runs
  • Ephemeral nodes: Set cache=False to skip caching for frequently-changing outputs and their downstream dependents
  • Immutability: Artifacts are frozen once created
  • Determinism: Operations rely only on explicit inputs
  • Serializable graphs: Versioned JSON wire format for storage, transmission, and interoperability
  • Demand execution: Callers request one or more outputs; unreachable graph branches are skipped
  • Conditional composition: SwitchNode selects graph-local branches without touching inactive branches
  • YAML authoring: Optional human-editable graph documents, including resource-backed subgraph grafting

Installation

# From PyPI
pip install invariant-core

# Optional YAML authoring and resource-backed subgraph grafting
pip install invariant-core[yaml,resources]

# From source
git clone https://github.com/kws/invariant-core
cd invariant-core
uv sync

Quick Start

from invariant import Executor, Node, OpRegistry, cel, ref
from invariant.ops import stdlib
from invariant.store.memory import MemoryStore

# Create registry and register operations
registry = OpRegistry()
registry.register_package("stdlib", stdlib)

# Pipeline: compute (3 * 4) + (5 * 6), then scale the total
#
#   ab ──┐
#        ├── total ── scaled
#   cd ──┘
#
# Literal values flow directly into params — no wrapper nodes needed.
# ref()  passes a computed artifact to a downstream op.
# cel()  evaluates a CEL (Common Expression Language) expression against
#        upstream artifacts, useful for extracting or transforming values
#        without a dedicated op.
graph = {
    "ab": Node(
        op_name="stdlib:multiply",
        params={"a": 3, "b": 4},                    # literal inputs
        deps=[]
    ),
    "cd": Node(
        op_name="stdlib:multiply",
        params={"a": 5, "b": 6},                    # literal inputs
        deps=[]
    ),
    "total": Node(
        op_name="stdlib:add",
        params={"a": ref("ab"), "b": ref("cd")},    # ref() passes artifacts directly
        deps=["ab", "cd"]
    ),
    "scaled": Node(
        op_name="stdlib:multiply",
        params={"a": ref("total"), "b": cel("ab + cd")},  # cel() computes from upstreams
        deps=["ab", "cd", "total"]
    ),
}

# Execute requested outputs
store = MemoryStore()
executor = Executor(registry=registry, store=store)
results = executor.execute(graph, ["ab", "cd", "total", "scaled"])

print(results["ab"])      # 12
print(results["cd"])      # 30
print(results["total"])   # 42
print(results["scaled"])  # 42 * (12 + 30) = 1764

Architecture

Invariant separates graph definition from demand execution in two phases:

  1. Phase 1: Context Resolution - Builds input manifests for active nodes
  2. Phase 2: Action Execution - Executes operations or retrieves from cache

Documentation

Document Description
docs/architecture.md System overview, design philosophy, and reference test pipeline
docs/expressions.md Normative reference for ref(), cel(), ${...} parameter markers and the CEL expression language
docs/executor.md Normative reference for demand execution, graph shaking, caching, and artifact storage
docs/serialization.md Normative reference for graph JSON/YAML documents, data URIs, Node, SubGraphNode, SwitchNode, ref, and cel
examples/README.md Runnable examples with walkthroughs, DAG diagrams, and run instructions
AGENTS.md Quick-start guide for AI agents working with this codebase

Development

# Run tests
uv run pytest

# Run tests with coverage
uv run pytest --cov=src --cov-report=html

# Run linting
uv run ruff check src/ tests/

# Format code
uv run ruff format src/ tests/

License

MIT License - see LICENSE for details.

Release files for invariant-core 0.6.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 invariant-core 0.6.0
File Size Uploaded
invariant_core-0.6.0.tar.gz 291.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for invariant-core 0.6.0
File Interpreter ABI Platform
invariant_core-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 337.8 kB

Release files / invariant_core-0.6.0.tar.gz

Download URL invariant_core-0.6.0.tar.gz
Size 291.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ad84cf3c8583dba3c0d15b9fac0047c06d64addcf2cb5c02434ec411fbb75484
BLAKE2b-256 checksum
How to use checksums
bad48d16bee366226d8f2d28c81f05214791ebdf84001a8a3d4374c93240378b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 6, 2026.

Transparency log

Release files / invariant_core-0.6.0-py3-none-any.whl

Download URL invariant_core-0.6.0-py3-none-any.whl
Size 46.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
127681edfd694c7cac00b1bcd1f868df5c45e580967ea4a62419c48766351915
BLAKE2b-256 checksum
How to use checksums
999268d8d7e2a02aa4a6d9a2bf9bfdeac5bc86c0ccb7e651ca053335fd0b034d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 6, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

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