sagah
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
Metadata
Release files for sagah 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sagah-0.1.0.tar.gz | 4.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sagah-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.3 kB
Release files / sagah-0.1.0.tar.gz
| Download URL | sagah-0.1.0.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fd381434d1459ef50fe5d18651aecbe68feb0a2cce5f11e4aa27c06a69e1d948
|
|
BLAKE2b-256 checksum How to use checksums |
d6c469e705a1c1a5547840a09f2ea19dafd7cd8db42b6cefb1a882340a1e3604
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.7 CPython/3.6.14 Linux/4.15.0-1103-aws
|
Release files / sagah-0.1.0-py3-none-any.whl
| Download URL | sagah-0.1.0-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f248a154f9b3ef7f06b777bc2cae1e19f8cbb27aed181fa893dc63cd14d68b77
|
|
BLAKE2b-256 checksum How to use checksums |
a4e49de4c101ca9fa68cb37951e1c40f54e9f0d231b82937bbb22ec53a1ed4c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.7 CPython/3.6.14 Linux/4.15.0-1103-aws
|