A distributed leader election python package using postgresql notify.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file notifelect-0.0.3.tar.gz
.
File metadata
- Download URL: notifelect-0.0.3.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ea0e35f25a6db6d8ca321c205df466a4770395d515e9eb687ae073e55b26526 |
|
MD5 | 6d04eef88e4295d4a36d59327fa39df9 |
|
BLAKE2b-256 | 8b7ca3e6cb7ccd822e1f7579813db0c7125482dd38682f9d253ce380313bdb76 |
File details
Details for the file notifelect-0.0.3-py3-none-any.whl
.
File metadata
- Download URL: notifelect-0.0.3-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 009cdced3335bd5cf5ea64d47dcb34934cfb63e21650f3c63306ac5d33137da7 |
|
MD5 | 6ee368cf8ea418fa169d6f406b160e3e |
|
BLAKE2b-256 | f107be49f6f0474723cd3e1e484e3ad63b977ec4ec30eae45e58d6469466cdfc |