Skip to main content

Saga Framework

Overview

The Saga Pattern Implementation in Python is a robust and flexible library that facilitates managing complex transactions in distributed systems using the Saga pattern. It ensures data consistency and reliability by handling long-running transactions through a sequence of local transactions, each with corresponding compensating actions in case of failures.

Features

  • Task Management: Easily add and manage a sequence of tasks that constitute a saga.
  • Compensation Mechanism: Automatically compensates completed tasks in reverse order if a failure occurs.
  • Context Handling: Share contextual information across tasks seamlessly.
  • Comprehensive Logging: Detailed logging of saga execution, task progress, and error handling.
  • Customizable Logging: Inject custom loggers to tailor logging to your needs.
  • Exception Handling: Robust error handling with custom exceptions for clear error propagation.
  • Extensible Design: Modular architecture allowing for easy extension and customization.

Table of Contents

Installation

You can install the Saga library using pip:

pip install saga-framework

Usage Here's a simple example demonstrating how to define and execute a saga with tasks and compensations:

from saga import Saga, Task, Context
from saga.logging import SagaLogger
from saga.errors import SagaExecutionException

# Define your tasks
class CreateOrderTask(Task):
    def execute(self, context: Context):
        # Logic to create an order
        print("Order created.")

    def compensate(self, context: Context):
        # Logic to compensate order creation
        print("Order creation compensated.")

class ChargePaymentTask(Task):
    def execute(self, context: Context):
        # Logic to charge payment
        print("Payment charged.")
        # Simulate failure
        raise SagaExecutionException("Payment failed.")

    def compensate(self, context: Context):
        # Logic to refund payment
        print("Payment refunded.")

# Initialize Saga with a logger
logger = SagaLogger()
saga = Saga(logger=logger)

# Add tasks to the saga
saga.add_task(CreateOrderTask())
saga.add_task(ChargePaymentTask())

# Execute the saga
try:
    saga.execute()
except SagaExecutionException as e:
    print(f"Saga failed: {e}")

Metadata

Release files for saga-framework-python 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for saga-framework-python 0.0.2
File Size Uploaded
saga_framework_python-0.0.2.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for saga-framework-python 0.0.2
File Interpreter ABI Platform
saga_framework_python-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 17.9 kB

Release files / saga_framework_python-0.0.2.tar.gz

Download URL saga_framework_python-0.0.2.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
6617201966e29737e77239d5d12b48becfec63b71dae5c296d75653ce1666f4d
BLAKE2b-256 checksum
How to use checksums
2a3f88b21cb0e68f31e9ca959dc5ee04b59290da8363a4852306803d43b93dd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release files / saga_framework_python-0.0.2-py3-none-any.whl

Download URL saga_framework_python-0.0.2-py3-none-any.whl
Size 9.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
87b90985b96559944ed2b32432cbc133ebf975c33a20da7c5eeaf55f0dc192db
BLAKE2b-256 checksum
How to use checksums
0a252a7e2f905a00f7ce792713212357dacffcd24e15b72ad37459065eade0c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.5

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page