Skip to main content

A service bus library.

Project description

Project

Status

CI/CD

Latest Release CI Documentation Building

Quality

https://codecov.io/github/mersal-org/mersal/graph/badge.svg?token=3219SZABYN

Package

PyPI - Version PyPI - Support Python Versions Mersal PyPI - Downloads

Meta

License - MIT types - ty types - Basedpyright types - Mypy linting - Ruff

Mersal is a service bus library for Python. It helps you build message driven systems (a.k.a event driven architecture).

There will be more here eventually but here is an LLM summary of core features in Mersal:

  • Transport agnostic: AWS SNS/SQS, GCP Pub/Sub, RabbitMQ, Azure Servicebus, it’s your choice!

  • Pub/sub - subscribe to events across independently running apps, with autosubscribe support so wiring stays out of your way.

  • Sagas - coordinate a business process that spans multiple messages over time, with pluggable storage for the saga’s state.

  • The outbox pattern - persist outgoing messages in the same transaction as your business data, so a handler’s side effects and its database write succeed or fail together.

  • Idempotent handling - process the same message more than once without corrupting state.

  • Retries and error handling - configurable retry strategies with dead-lettering to an error queue once a message keeps failing, so nothing is silently dropped.

  • A transport bridge - route messages to specific destinations through a different transport than the rest of the system, useful for migrations, cost/efficiency tradeoffs, or testing.

  • Pluggable persistence, and serialization

  • Unit of work and a request/response-style pipeline - hook into message handling to add your own cross-cutting behavior, the same way middleware works in a web framework.

Head to the quick start to build a small message-driven system in a few minutes, or the full documentation for everything else.

Acknowledgments ♥

This is a personal acknowledgment from myself (@abdulhaq-e), the main author of Mersal.

First, to the book Architecture Patterns with Python (“Cosmic Python”) and its two authors, Harry Percival (@hjwp) and Bob Gregory (@bobthemighty). Its impact on my career is substantial and cannot be compared to any other material I came by. In addition, the book is why we have Mersal.

I was following the book before its official release via its git repository. I completed every example, studied all patterns, read all the side material and years later, I still go back to it. It is like watching and rewatching a favourite TV show! I really recommend anyone who is building systems using Python (or any other language actually) to study from this book, especially if someone wants to adopt Domain Driven Design (DDD).

In Part 2 of the book, the authors introduce the concept of Event Driven Architecture and the idea of a “message bus”. Once I started building a system and applying my learnings, the system message bus was more or less the message bus from the book. From one system to the next, the bus was extracted into a reusable package and for years it was “pyservicebus”. This now brings me to the second acknowledgment. Before that, thank you, Harry and Bob, for writing the book, and for putting so much effort into it and for writing/releasing it as an open book. ♥

The current state of Mersal is significantly different than how pyservicebus looked like. I still have the commits stored somewhere with all the cursing and trials. Building a service bus that abstracts transport mechanism isn’t an easy job. So why not build on the shoulder of giants. While learning more about the concept of a message bus, I did come by NServiceBus and they have great learning materials regarding the topic and message driven architecture in general. NServicebus is OSS but their product is what you can consider as a gigantic framework with all batteries included. When looking for inspiration for Mersal, I wanted something lighter and that’s when I found Rebus, it’s a .NET service bus designed to provide a “lean” offering. While Mersal might have drifted since, I’d still agree to call it the “Python replica of Rebus”. Huge thanks to Mogens Heller Grabe (@mookid8000), Rebus’s core developer, for building and maintaining it so well for so long that it was worth learning from and borrowing this much from. ♥

Finally, a shout out to Litestar. A number of things in Mersal, from small utilities to bigger design decisions, were copied or heavily inspired by code in the Litestar organization’s repositories. Thanks to everyone there for building something worth learning from and borrowing from as well.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mersal-0.3.0.tar.gz (298.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mersal-0.3.0-py3-none-any.whl (121.2 kB view details)

Uploaded Python 3

File details

Details for the file mersal-0.3.0.tar.gz.

File metadata

  • Download URL: mersal-0.3.0.tar.gz
  • Upload date:
  • Size: 298.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for mersal-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b17690e5fbbd5521155b34aeaf76fb0f9bb5a5f9f89e9ba34d41307002f0aa19
MD5 72615be171e94eb138dc4283cf5d5cb0
BLAKE2b-256 cb782050c663e5288fc63ed4d20edd323ea65f00f94069470be72ca4edb105ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for mersal-0.3.0.tar.gz:

Publisher: publish.yml on mersal-org/mersal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mersal-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: mersal-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 121.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for mersal-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 38824b2d0c451df345e5b0226330e110f73738a11565bd70dc6da54123baeac5
MD5 616162e9a53ead8c2a80cb4fb717e46b
BLAKE2b-256 69ae5f36fea047d9232aa63ca327430a550653b84a44a416a5227397816c63c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for mersal-0.3.0-py3-none-any.whl:

Publisher: publish.yml on mersal-org/mersal

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page