Skip to main content

Orchestrated, async sagas in Python

Project description

sagah

License

Orchestrated, async sagas in Python

Table of Contents:

Installation

sagah requires Python 3.6 or above.

pip install sagah

Guide

Example usage:

from sagah import Saga

state = {"counter": 0}

def incr():
    state["counter"] += 1

def decr():
    state["counter"] -= 1

with Saga() as saga:
    await saga.action(incr, decr)
    await saga.action(incr, decr)

assert state["counter"] == 2

If some action fails, the compensating functions from previous transactions will be called to restore the state:

from sagah import Saga

state = {"counter": 0}

def incr():
    state["counter"] += 1

def decr():
    state["counter"] -= 1

def fail():
    raise ValueError("oops")

try:
    with Saga() as saga:
        await saga.action(incr, decr)
        await saga.action(incr, decr)
        await saga.action(fail, noop)
except Exception:
    assert state["counter"] == 0

Development

To develop sagah, install dependencies and enable the pre-commit hook:

pip install pre-commit poetry
poetry install
pre-commit install

To run tests:

poetry run pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sagah-0.1.0.tar.gz (4.1 kB view hashes)

Uploaded Source

Built Distribution

sagah-0.1.0-py3-none-any.whl (4.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page