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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file sagah-0.1.0.tar.gz.

File metadata

  • Download URL: sagah-0.1.0.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.7 CPython/3.6.14 Linux/4.15.0-1103-aws

File hashes

Hashes for sagah-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fd381434d1459ef50fe5d18651aecbe68feb0a2cce5f11e4aa27c06a69e1d948
MD5 768510ca5d76b41bf34ba898d0a001c9
BLAKE2b-256 d6c469e705a1c1a5547840a09f2ea19dafd7cd8db42b6cefb1a882340a1e3604

See more details on using hashes here.

File details

Details for the file sagah-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sagah-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.7 CPython/3.6.14 Linux/4.15.0-1103-aws

File hashes

Hashes for sagah-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f248a154f9b3ef7f06b777bc2cae1e19f8cbb27aed181fa893dc63cd14d68b77
MD5 79dded548d6f9f5543b4123bd8c23eb2
BLAKE2b-256 a4e49de4c101ca9fa68cb37951e1c40f54e9f0d231b82937bbb22ec53a1ed4c4

See more details on using hashes here.

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