The official Python implementation of the Ergon Framework—a transaction-first, observability-native execution engine for building high-throughput automation pipelines.
Installation
pip install ergon-framework-python
Connector integrations are optional extras, so a core installation does not
pull in client libraries that your application does not use:
Available extras are rabbitmq, sqs, postgres, pipefy, excel,
ergon-platform, nylas, and outlook.
Outlook / Microsoft Graph
pip install 'ergon-framework-python[outlook]'
The Outlook connector talks to Microsoft Graph with Entra application
credentials. Consuming messages and attachments needs Mail.Read; marking,
categorizing, moving, and deleting need Mail.ReadWrite; send, reply, and
forward need Mail.Send. Graph $filter and $search cannot be combined.
Create a task by inheriting from ConsumerTask and implementing process_transaction:
from typing import Any
from ergon.task.mixins import ConsumerTask
from ergon.connector import Transaction
class OrderProcessor(ConsumerTask):
"""Consumes order transactions and processes them."""
def process_transaction(self, transaction: Transaction) -> Any:
# Pure business logic—no I/O, no retries, no protocol details
order = transaction.payload
total = order["quantity"] * order["unit_price"]
return {"order_id": order["id"], "total": total, "status": "processed"}
def handle_process_success(self, transaction: Transaction, result: Any):
# Called after successful processing
self.output_connector.dispatch_transactions([
Transaction(id=f"out-{transaction.id}", payload=result, metadata={})
])
def handle_process_exception(self, transaction: Transaction, exc: Exception):
# Called when processing fails (after all retries exhausted)
self.dlq_connector.dispatch_transactions([transaction])
2. Create a Connector
Connectors bridge external systems to the transaction interface:
from typing import List
from ergon.connector import Connector, Transaction
import uuid
class RabbitMQConnector(Connector):
def __init__(self, queue_name: str, connection_url: str):
self.queue_name = queue_name
# Initialize your RabbitMQ client here
self.client = create_rabbitmq_client(connection_url)
def fetch_transactions(self, batch_size: int, **kwargs) -> List[Transaction]:
messages = self.client.consume(self.queue_name, max_messages=batch_size)
return [
Transaction(
id=str(uuid.uuid4()),
payload=msg.body,
metadata={"delivery_tag": msg.delivery_tag, "routing_key": msg.routing_key}
)
for msg in messages
]
def dispatch_transactions(self, transactions: List[Transaction], **kwargs):
for tx in transactions:
self.client.publish(self.queue_name, tx.payload)
3. Configure and Run
Use TaskConfig to wire everything together:
from ergon.task import TaskConfig, runner, policies
from ergon.connector import ConnectorConfig
# Configure the consumer policy
consumer_policy = policies.ConsumerPolicy()
consumer_policy.name = "consumer"
consumer_policy.loop.concurrency.value = 5 # Process 5 transactions in parallel
consumer_policy.loop.batch.size = 10 # Fetch 10 at a time
consumer_policy.loop.streaming = True # Keep polling for new messages
consumer_policy.process.retry.max_attempts = 3 # Retry failed processing 3 times
consumer_policy.process.retry.backoff = 1.0 # Start with 1s backoff
consumer_policy.process.retry.backoff_multiplier = 2.0 # Double each retry
# Create the task configuration
config = TaskConfig(
name="order-processor",
task=OrderProcessor,
max_workers=1,
connectors={
"input": ConnectorConfig(
connector=RabbitMQConnector,
kwargs={"queue_name": "orders", "connection_url": "amqp://localhost"}
),
"output": ConnectorConfig(
connector=RabbitMQConnector,
kwargs={"queue_name": "processed-orders", "connection_url": "amqp://localhost"}
),
},
policies=[consumer_policy],
)
# Run the task
if __name__ == "__main__":
runner.run(config)
The framework handles the loop, retry logic, telemetry, and graceful shutdown automatically.
The Transaction Object
In the Python SDK, transactions are implemented as immutable Pydantic models:
from ergon.connector import Transaction
# Transactions are created by Connectors when fetching data
tx = Transaction(
id="tx-001", # Unique identifier for tracing
payload={"order_id": 123, "amount": 99.99}, # The actual data
metadata={"source": "rabbitmq", "queue": "orders"} # Contextual info
)
Transactions are frozen (immutable) once created via Pydantic's frozen=True configuration.
Task Classes
The Python SDK provides ready-to-use task classes:
Best for CPU-bound processing or legacy libraries:
from ergon.task.mixins import ConsumerTask
class SyncProcessor(ConsumerTask):
def process_transaction(self, transaction):
# Runs in ThreadPoolExecutor
return heavy_computation(transaction.payload)
Concurrency controlled by policy.loop.concurrency.value
Each transaction processed in its own thread
Multi-process scaling via max_workers > 1
Asynchronous Tasks
Best for I/O-bound workloads with high concurrency:
from ergon.task.mixins import AsyncConsumerTask
class AsyncProcessor(AsyncConsumerTask):
async def process_transaction(self, transaction):
# Runs in asyncio event loop
result = await self.http_client.post(transaction.payload)
return result
Concurrency controlled by asyncio.Semaphore
Thousands of concurrent operations with minimal overhead
Perfect for API calls, database queries, network I/O
Dependency Injection
Tasks receive all dependencies automatically via the TaskMeta metaclass:
class EnrichmentTask(ConsumerTask):
def process_transaction(self, transaction: Transaction) -> Any:
# Access connectors as self.{name}_connector
count = self.input_connector.get_transactions_count()
# Access services as self.{name}_service
enriched = self.openai_service.complete(transaction.payload["text"])
# Access policies as self.{name}_policy
timeout = self.consumer_policy.loop.timeout
return {"enriched": enriched, "pending": count}