Notifelect: Robust Leader Election for Distributed Systems Using PostgreSQL NOTIFY
Notifelect is a Python package designed for seamless leader election in distributed systems. It utilizes the NOTIFY feature of PostgreSQL to manage elections, offering a robust and reliable solution for systems requiring fault tolerance and consistency across nodes. Leveraging the Bully algorithm, Notifelect ensures dynamic leader selection with minimal configuration.
Why Notifelect?
- Efficient Leader Elections: Utilizes PostgreSQL's NOTIFY and sequences for efficient and accurate leader determination.
- Asynchronous Operations: Built with asyncio, allowing for non-blocking, event-driven communication.
- Easy to Integrate: Simple API that fits naturally into existing Python applications.
Enhance your distributed systems with Notifelect’s efficient leader election mechanism for improved reliability and performance.
Getting Started
Installation is straightforward using pip:
pip install notifelect
python -m notifelect install # Set up necessary database sequences
Quick Example
Simulate a leader election among N processes:
import asyncio
import contextlib
import random
import sys
from typing import AsyncGenerator
import asyncpg
from notifelect import election_manager
@contextlib.asynccontextmanager
async def connection() -> AsyncGenerator[asyncpg.Connection, None]:
conn = await asyncpg.connect()
try:
yield conn
finally:
await conn.close()
async def process() -> None:
await asyncio.sleep(random.random() * 2)
async with connection() as conn, election_manager.Coordinator(conn):
await asyncio.sleep(float('inf'))
async def main() -> None:
N = int(sys.argv[1])
processes = [process() for _ in range(N)]
await asyncio.gather(*processes)
if __name__ == "__main__":
asyncio.run(main())
Enhancements
- Clear Value Proposition: Begins with why Notifelect is beneficial and its specific features.
- Streamlined Setup and Example: Simplified instructions and example for easier comprehension and quicker start.
- Engaging Introduction: More direct and impactful opening to grab attention immediately.
These changes are intended to make the README not only more attractive but also more user-friendly, encouraging community use and contributions.
Metadata
Release files for notifelect 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 | |
|---|---|---|---|
| notifelect-0.0.3.tar.gz | 14.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| notifelect-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.3 kB
Release files / notifelect-0.0.3.tar.gz
| Download URL | notifelect-0.0.3.tar.gz |
|---|---|
| Size | 14.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7ea0e35f25a6db6d8ca321c205df466a4770395d515e9eb687ae073e55b26526
|
|
BLAKE2b-256 checksum How to use checksums |
8b7ca3e6cb7ccd822e1f7579813db0c7125482dd38682f9d253ce380313bdb76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / notifelect-0.0.3-py3-none-any.whl
| Download URL | notifelect-0.0.3-py3-none-any.whl |
|---|---|
| Size | 10.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
009cdced3335bd5cf5ea64d47dcb34934cfb63e21650f3c63306ac5d33137da7
|
|
BLAKE2b-256 checksum How to use checksums |
f107be49f6f0474723cd3e1e484e3ad63b977ec4ec30eae45e58d6469466cdfc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|