How to use Decisions in your Python application

Introduction

decision_lab is a Python library that provides a simple and intuitive interface for creating and managing DECISIONS that can be accessed via APIs. With decision_lab, you can make code behavior changes without changing the code itself, saving time and money on development and maintenance.

Python Package (pypi)

View package: Python Package (pypi)

Installation

pip install decisionlab

Usage

  • There are 2 types of tokens: read only, and read and write, both are compatible with the python library

Read only

from decisionlab import DecisionLab
        
decision_lab = DecisionLab(token='your_read_only_token')

Use Decisions in your code

# Get the list of decisions
In [3]: dl = DecisionLab(token='dfda3ffe-0cd7-48e4-9034-c926c580bee6')

In [4]: dl.list_decisions()
Out[4]: ['decision_name', 'decision_name2'] 

Get the value of a decision and use it in your code

dl.get_decision('decision_name')
        >> 'decision_value'

Read and write

from decisionlab import DecisionLab
            dl = DecisionLab(token='your_read_and_write_token', is_read_write=True)

Write a decision

Rewriting of decisions from the library is also possible with this token

dl.update_decision_value('decision_name', 'decision_value')

Decision Duty

Decision Duty is a feature that allows for simple but powerful alerts to be sent via email when a decision is change via the api. If a decision name starts with “DUTY&rduo; and it is changed with the api (i.e using this library) then an email will be sent to the team members. This is useful for critical systems so that if a decision is changed, the team is notified.


                try: 
                    critical_function_that_should_never_fail()
                except Exception as e:    
                    error = str(e)
                    dl.update_decision_value('DUTY_decision_name', f'ERROR: {error}')')

This will sent an email similar to:

🚨EMERGENCY
            The duty decision DUTY_emergency_demo has been updated to: 
            Exception on attempt 3: Traceback (most recent call last):
             File "/critical_system.py",
              line 13, in wrapper_retry return func(*args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^ File "", line 4,
               in demo_function raise ValueError("Demo error") ValueError: Demo error