SAGAS
A simple async sagas implementation
Installation
$ pip install pysagas
Usage
Simple example
import asyncio
from sagas import SagaBuilder
counter = [10, 20]
amount = 30
def add(amount, index):
"""Increments array index by amount
Args:
amount (int): increment value
index (int): index of value to increment
"""
counter[index] += amount
def decrement(amount, index):
"""Decrements array index by amount
Args:
amount (int): decrement value
index (int): index of value to decrement
"""
counter[index] -= amount
return counter
saga_builder = SagaBuilder.create()
saga = saga_builder\
.add_step(lambda: add(amount, 0), lambda: decrement(amount, 0))\
.add_step(lambda: add(amount, 1), lambda: decrement(amount, 1))\
.build()
if __name__ == "__main__":
asyncio.run(saga.run(exceptions=(OSError)))
print(counter) # [40, 50]
Failure example
If one step fails, the compensating functions for the executed steps run and the counter values are compensated
import asyncio
from sagas import SagaBuilder
counter = [10, 20]
amount = 30
def add(amount, index):
"""Increments array index by amount
Args:
amount (int): increment value
index (int): index of value to increment
"""
counter[index] += amount
raise Exception('error occurred')
def decrement(amount, index):
"""Decrements array index by amount
Args:
amount (int): decrement value
index (int): index of value to decrement
"""
counter[index] -= amount
return counter
saga_builder = SagaBuilder.create()
saga = saga_builder\
.add_step(lambda: add(amount, 0), lambda: decrement(amount, 0))\
.add_step(lambda: add(amount, 1), lambda: decrement(amount, 1))\
.build()
if __name__ == "__main__":
asyncio.run(saga.run(exceptions=(OSError, Exception)))
print(counter) # [10, 20]
CHANGES
- add test step
- add unit tests
- ch(docs):add documentation- add readme docs- add usage examples
0.0.2
- rename package
- add changelog
- add setup.py file
0.0.1
- remove example
- Setup publishing to pypi
- initial commit
Metadata
Release files for pysagas 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pysagas-0.0.3.tar.gz | 5.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pysagas-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.3 kB
Release files / pysagas-0.0.3.tar.gz
| Download URL | pysagas-0.0.3.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fac84cabaadb0cc018ff0b9aba7f2b45238dc3c97fe09015de53d32c2133d454
|
|
BLAKE2b-256 checksum How to use checksums |
7b903ca013eef52c0b9dc6db715af2d2fffc8150f3aafaf565d32e185bd2ed6d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
|
Release files / pysagas-0.0.3-py3-none-any.whl
| Download URL | pysagas-0.0.3-py3-none-any.whl |
|---|---|
| Size | 2.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
235758a594b6f3b043d67b34f43b96362cac1061f24ce90e215718146136a4ee
|
|
BLAKE2b-256 checksum How to use checksums |
094ed14db12e038bb6f9063a8e97071a8826063c7dd7d6a10fd56e2fd2112d7b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.8.1
|
Security for pysagas 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.