Skip to main content
Process DataFrames efficiently using the ZEN Engine with Polars map_elements.

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

Use pl.struct to combine multiple columns for evaluation:

Extracting result fields

Extract individual fields from results:

Error handling

Return structured results with success/error information:

Lazy evaluation

Filter data before processing:

Batch processing

Process large files in batches:

Parallel processing

For CPU-bound workloads, use multiprocessing with the same pattern:

Multiple decisions

Evaluate multiple rule sets from a single loaders dict:

Best practices

Precompile on initialize. The ZenEvaluator converts dict[str, str] to dict[str, ZenDecisionContent] once. The loader returns precompiled content for maximum performance. Use engine.evaluate directly. No need to call create_decision - the engine’s loader handles everything. Use loaders dict. Store rules as dict[str, str] (picklable for multiprocessing), precompile once on init. Use map_elements for UDF-like behavior. This is Polars’ equivalent of Spark UDFs. Use pl.struct for multiple columns. Combine columns into a struct before applying map_elements. Use lazy evaluation for filtering. Apply predicates with scan_parquet before collecting to reduce data processed. Use multiprocessing for large datasets. The GIL limits threading benefits; use process-based parallelism instead.
The ZenEvaluator precompiles JSON strings to ZenDecisionContent on first initialization. The engine’s loader returns precompiled content, avoiding repeated JSON parsing. This provides optimal performance for high-throughput processing.