Metadata-Version: 2.4
Name: patchwork-node
Version: 1.0.0
Summary: Worker node for Patchwork - The distributed asynchronous microframework
Author: Paweł Pecio
License: MIT
Classifier: Development Status :: 5 - Production/Stable
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Requires-Python: >=3.11.0
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: aiohttp>=3.9
Requires-Dist: psutil>=5.8.0
Requires-Dist: humanize>=3.11.0
Requires-Dist: patchwork-core<3,>=2.0.0
Provides-Extra: metrics
Requires-Dist: prometheus-client>=0.20; extra == "metrics"
Provides-Extra: docs
Requires-Dist: mkdocs<2,==1.6.1; extra == "docs"
Requires-Dist: mkdocs-material; extra == "docs"
Requires-Dist: mkdocstrings[python]; extra == "docs"
Dynamic: license-file

# Patchwork Node

Worker node for Patchwork - an asynchronous, event-driven microframework for distributed services.

The node fetches messages from a message broker, routes them to async handlers, runs handlers on processing
units and settles messages: commits, retries, reroutes or backoffs them.

## Requirements

* Python 3.11+
* `patchwork-core` 2.0+ and a broker client package, eg. `patchwork-client-kafka` or `patchwork-client-redis`

## Installation

```bash
pip install patchwork-node
```

Optional extras: `patchwork-node[metrics]` for Prometheus metrics.

## Example

```python
from patchwork.core import Message
from patchwork.core.client.local import LocalBroker, LocalPublisher, LocalSubscriber
from patchwork.node import Worker
from patchwork.node.core import TaskRouter
from patchwork.node.node import run
from patchwork.node.processor import InlineUnit

router = TaskRouter(processor=InlineUnit(concurrency=10))


@router.on("user.created")
async def user_created(message: Message):
    print(message.get_payload())


broker = LocalBroker()
worker = Worker(
    subscriber=LocalSubscriber(broker=broker, queues=["users"]),
    publisher=LocalPublisher(broker=broker),
)
worker.add_router(router)
run(worker)
```

## Documentation

https://patchwork-framework.gitlab.io/node
