fast-decision
A high-performance rule engine written in Rust with Python bindings, designed for applications that need to evaluate complex business rules with minimal latency and maximum throughput.
Features
- High Performance: Rust-powered engine with zero-cost abstractions
- Priority-based Execution: Rules sorted by priority (lower number = higher priority)
- Stop-on-First: Per-category flag to stop after first match
- MongoDB-style Operators: Familiar syntax with
$eq,$ne,$gt,$lt,$gte,$lte,$and,$or - Complex Logic: Support for nested AND/OR predicates
- Python Bindings: Native performance with idiomatic Python API via PyO3
- Memory Efficient: Minimal allocations in hot path, optimized data structures
- Benchmarked: Built-in performance benchmarks with Criterion
Use Cases
- Business rule engines
- Dynamic pricing systems
- Feature flags and A/B testing
- Access control and authorization
- Data validation and filtering
- Workflow automation
Installation
Rust
Add to your Cargo.toml:
[]
= "0.1"
Python
Or install from source:
Quick Start
Rust Example
use ;
use json;
Python Example
See python/README.md for detailed Python documentation.
# Load rules from JSON file
=
# Execute rules
=
=
# Output: ['Gold_Discount']
Rule Format
Rules are defined in JSON with MongoDB-style syntax:
Supported Operators
| Operator | Description | Example |
|---|---|---|
$eq |
Equal | {"age": {"$eq": 18}} |
$ne |
Not equal | {"status": {"$ne": "inactive"}} |
$gt |
Greater than | {"score": {"$gt": 100}} |
$lt |
Less than | {"price": {"$lt": 50}} |
$gte |
Greater than or equal | {"age": {"$gte": 21}} |
$lte |
Less than or equal | {"count": {"$lte": 10}} |
Logical Operators
Implicit AND - Multiple conditions in one object:
Explicit OR - Use $or:
Nested Logic:
Performance
Benchmarks
Run benchmarks:
Optimization Features
- Rust backend: Native machine code performance
- Zero allocations in hot execution path
- Inline functions: Critical comparison functions marked
#[inline(always)] - Optimized data structures:
Box<[String]>for path tokens,#[repr(u8)]for operators - Pre-sorted rules: Rules sorted by priority at load time
- Direct conversion: Python dict → Rust without intermediate JSON serialization
- Link Time Optimization (LTO): Enabled in release profile
Performance Characteristics
- Rule evaluation: O(n) where n = number of rules in requested categories
- Field lookup: O(d) where d = depth of nested field path
- Memory: Minimal allocations during execution (only for results)
Development
# Run tests
# Run Rust examples
# Run benchmarks
# Build documentation
# Run Python tests
# Run Python examples
Contributing
See CONTRIBUTING.md for development guidelines.
Architecture
fast-decision/
├── src/ # Rust core engine
│ ├── lib.rs # Python bindings (PyO3)
│ ├── engine.rs # Rule execution engine
│ └── types.rs # Data structures
├── benches/ # Performance benchmarks
├── examples/ # Rust examples
├── python/ # Python bindings and examples
│ ├── examples/ # Usage examples
│ └── tests/ # Tests
├── Cargo.toml # Rust configuration
└── pyproject.toml # Python packaging
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.