Skip to main content
Process large datasets with distributed rule evaluation using PySpark UDFs and broadcast variables.

Installation

Singleton evaluator

Use a singleton pattern with precompiled ZenDecisionContent for optimal performance:

Basic usage

Cloud storage

Load all decisions from a single zip file at startup for optimal performance.

AWS S3

Azure Blob Storage

Google Cloud Storage

Processing structured columns

Process data from separate columns:

Extracting result fields

Return specific result fields directly:

Error handling

Return structured results with success/error information:

Multiple decisions

Evaluate multiple rule sets from a single loaders dict:

Performance tuning

Repartition for parallelism

Helper function for UDF creation

Best practices

Precompile on initialize. The ZenEvaluator converts dict[str, str] to dict[str, ZenDecisionContent] once, then the loader returns precompiled content for maximum performance. Broadcast loaders dict. Broadcast dict[str, str] (picklable) to all workers. Each worker precompiles once on first use. Use engine.evaluate directly. No need to call create_decision - the engine’s loader handles everything. Repartition for parallelism. Match partition count to cluster parallelism (typically 2-4x cores). Use Parquet for I/O. Parquet provides efficient columnar storage and predicate pushdown.
The ZenEvaluator precompiles JSON strings to ZenDecisionContent on first initialization per worker. The engine’s loader then returns precompiled content, avoiding repeated JSON parsing. This provides optimal performance for high-throughput processing.