Files
zen/bindings/python
Stefan 7fade4435c feat(trace): trace format v1 with TraceCollector on the compiled engine
Compiled engine only; the interpreted engine keeps legacy traces. The
interpreted graph, policy and function code is unchanged from
release/2.2: asked for a trace (true, v1 or legacy) it returns its
legacy trace, never converts to v1, and ignores now, timezone and seed.

- trace format v1 inside the engine (compiled/trace), public as
  zen_engine::trace: convert (legacy to v1), restore (v1 to legacy),
  inspect and redact, with the native encoder and policy writer, and
  TraceFormat, TraceDocument, PolicyTrace and TraceBatch; no separate
  crate
- TraceFormat option (off, v1, legacy) replacing EvaluationTraceKind on
  every evaluation path; on the compiled engine legacy traces are
  restored from v1
- native TraceCollector for single-row, batch and columnar evaluation:
  a static template per compiled graph and typed facts pushed by the
  engine (rule hits, switch branches, expression results, sub-decision
  and loop levels), written as v1 without a legacy map
- native policy writer for executions, members, reads, writes and
  absence markers
- engine glue under compiled/ (compiled/trace/mod.rs,
  compiled/pinning.rs); workspace request, result and error types take
  the trace format and the policy trace as type parameters defaulting
  to the legacy types, with public aliases for TraceFormat and
  PolicyTrace; the response trace enum gains V1 and its policy variant
  holds a PolicyTrace
- pinned evaluation context on the compiled engine: now, timezone and
  seed options, one clock read per evaluation and per batch, per-row
  random streams (row i draws from row_seed(seed, i)) in every batch and
  columnar path, Date and Math.random pinned in compiled function nodes;
  evaluatedAt, timezone and seed in the envelope
- format additions: result rows for repeated keys, $redacted and
  $omitted with truncated, reserved context, requires flags
- now, timezone, seed and trace format options in the Node, Python, C
  and uniffi bindings
- golden tests: compiled v1 and legacy restore to the base traces for
  every spec case, interpreted variants return legacy traces equal to
  the base for any trace option, native and convert agree, batch and
  columnar rows equal single rows, timing stress, pinned and
  random-stream tests, and the interpreted engine ignores pinning;
  trace API, damaged-input, POC fixture (tests/fixtures/trace) and
  corpus tests, and the trace_corpus example for the POC cross-check
2026-11-04 17:46:43 +01:00
..
2023-03-29 22:14:37 +02:00
2026-10-21 17:48:01 +02:00
2026-10-21 17:48:01 +02:00
2023-04-02 21:10:05 +02:00
2025-08-25 12:33:07 +02:00

Python Rules Engine

Business logic humans can read and machines can run. One copy of your rules: the owner reads it, every system runs it.

License: MIT PyPI

GoRules ZEN Engine

ZEN Engine is a cross-platform, open-source Business Rules Engine (BRE) written in Rust with native Python bindings, alongside Node.js, Go, Java, Kotlin and .NET. Decisions evaluate in microseconds, run identically on every platform, and are stored as portable JSON. Loading the JSON is up to you: file system, database or service call.

Try it in the free Online Editor with a built-in simulator, or embed the open-source React JDM Editor in your own product. Learn more about the Python rules engine on the GoRules website.

Rules that read like sentences

Conditions are written the way the business says them, in the ZEN Expression Language. The developer view is one toggle away, and the two can never drift apart: there is only one source of truth, and this engine runs it.

Readable rules

Rules as graphs, or as documents

Model a decision on a visual canvas of decision tables, switches, expressions, functions and reusable sub-decisions. Or write it as a policy document with prose, typed data models and tables. Both compile to the same engine and return the same answers.

Graphs and documents

To go deeper, see the Python SDK documentation, the decision graph guide and the ZEN Expression Language reference.

What's new in 2.0

Version 2.0 is the first stable release of the new engine line:

  • Policy documents: model decisions as readable documents with typed data models, expressions, decision tables, match blocks and assertions. Policies compile to the same engine as graphs and return the same answers.
  • Workspace analysis: static type checking across policies and graphs. Type flow, exhaustiveness checking, write-conflict detection and precise diagnostics, all available before anything runs.
  • Per-column collect: decision table output columns can collect across all matching rows (tags[]) while the rest of the table stays first-match.
  • Pre-compiled engine: decisions are parsed and compiled once at load; evaluation is allocation-light and repeat-safe.
  • Hardened runtime: out-of-range numbers, arithmetic overflow and malformed inputs return errors or nulls instead of crashing the process.
  • Unified bindings: configurable loaders, batch evaluation and consistent error envelopes across Node.js, Python, Go and FFI consumers.

Installation

pip install zen-engine

Prebuilt wheels ship for Linux, macOS and Windows; no Rust toolchain required.

Quickstart

import zen

with open("./jdm_graph.json", "r") as f:
    content = f.read()

engine = zen.ZenEngine()

decision = engine.create_decision(content)
result = decision.evaluate({"input": 15})
print(result)

Loaders

For more advanced use cases where you want to load multiple decisions and reuse them across evaluations you can build loaders. When engine.evaluate is invoked it calls the loader with a key, expecting the content of the JDM decision graph in return.

import zen

def loader(key):
    with open("./jdm_directory/" + key, "r") as f:
        return f.read()

engine = zen.ZenEngine({"loader": loader})
result = engine.evaluate("jdm_graph1.json", {"input": 5})
print(result)

The same pattern works for loading from a REST API, S3, a database, or anywhere else. Full guides, including multi-decision graphs and batch evaluation, are in the Python SDK documentation.

Other platforms

The GoRules platform

The engine is open at the core; GoRules is the platform around it. Managed cloud, self-hosted, or embedded with no network hop. SOC 2 Type II.

AI that builds rules, and stays reviewable

An AI copilot and MCP server that edits rules, runs tests and explains decisions. It never deploys. Releases stay with your reviewers.

GoRules AI

Promote like a release, run like a binary

A release moves from testing to staging to production untouched. Approvals, instant rollback, and a paper trail for every change.

Governance

Prove it before it ships

Scenario suites run on every change, coverage is measured against decision paths, and every answer comes with a replayable trace.

Testing

Support matrix

Arch Python
linux-x64-gnu ✔️
linux-arm64-gnu ✔️
darwin-x64 ✔️
darwin-arm64 ✔️
win32-x64-msvc ✔️

We do not support linux-musl currently.

Contribution

The JDM standard is growing and we need to keep tight control over its development and roadmap, as a number of companies use GoRules ZEN Engine and GoRules BRMS. For this reason we can't accept code contributions at this moment, apart from help with documentation and additional tests.

License

MIT License