dur
durable
pypi i durable
dur

durable

Durable Rules Engine

by Jesus Ruiz

0.1.4 (see all)License:MIT
pypi i durable
Readme

Durable Rules

Durable Rules is a polyglot micro-framework for real-time, consistent and scalable coordination of events. With Durable Rules you can track and analyze information about things that happen (events) by combining data from multiple sources to infer more complicated circumstances.

A forward chaining algorithm (A.K.A. Rete) is used to evaluate massive streams of data. A simple, yet powerful meta-liguistic abstraction lets you define simple and complex rulesets, such as flowcharts, statecharts, nested statecharts, paralel and time driven flows.

The Durable Rules core engine is implemented in C, which enables ultra fast rule evaluation and inference as well as muti-language support. Durable Rules relies on state of the art technologies:

  • Node.js, Werkzeug, Sinatra are used to host rulesets written in JavaScript, Python and Ruby respectively.
  • Inference state is cached using Redis, which lets scaling out without giving up performance.
  • A web client based on D3.js provides powerful data visualization and test tools.

Below is an example on how easy it is to define a real-time fraud detection rule (three purchases over $100 within a 30 second interval).

####Ruby

require 'durable'

Durable.statechart :fraud do
  state :start do
    to :standby
  end
  state :standby do
    to :metering, when_(m.amount > 100) do
      start_timer :velocity, 30
    end
  end
  state :metering do
    to :fraud, when_(m.amount > 100, at_least(2)) do
      puts "fraud detected"
    end
    to :standby, when_(timeout :velocity) do
      puts "fraud cleared"
    end
  end
  state :fraud
end

Durable.run_all

####Python

from durable.lang import *

with statechart('fraud'):
    with state('start'):
        to('standby')

    with state('standby'):
        @to('metering')
        @when(m.amount > 100)
        def start_metering(s):
            s.start_timer('velocity', 30)

    with state('metering'):
        @to('fraud')
        @when((m.amount > 100).at_least(2))
        def report_fraud(s):
            print('fraud detected')

        @to('standby')
        @when(timeout('velocity'))
        def clear_fraud(s):
            print('fraud cleared')

    state('fraud')

run_all()

####JavaScript

var d = require('durable');

with (d.statechart('fraud')) {
    with (state('start')) {
        to('standby');
    }
    with (state('standby')) {
        to('metering').when(m.amount.gt(100), function (s) {
            s.startTimer('velocity', 30);
        });
    }
    with (state('metering')) {
        to('fraud').when(m.amount.gt(100).atLeast(2), function (s) {
            console.log('fraud detected');
        });
        to('standby').when(timeout('velocity'), function (s) {
            console.log('fraud cleared');  
        });
    }
    state('fraud');
}

d.runAll();

####Visual

Resources

To learn more:

Blog:

GitHub Stars

1K

LAST COMMIT

2yrs ago

MAINTAINERS

1

CONTRIBUTORS

22

OPEN ISSUES

188

OPEN PRs

5
VersionTagPublished
0.1.4
5yrs ago
No alternatives found
No tutorials found
Add a tutorial