Metadata-Version: 2.1
Name: notifelect
Version: 0.0.3
Summary: A distributed leader election python package using postgresql notify.
Author: janbjorge
License: MIT License
Project-URL: Documentation, https://github.com/janbjorge/notifelect/wiki
Project-URL: Homepage, https://github.com/janbjorge/notifelect/
Project-URL: Issues, https://github.com/janbjorge/notifelect/issues
Project-URL: Repository, https://github.com/janbjorge/notifelect/
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Web Environment
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python
Classifier: Topic :: Database
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Classifier: Topic :: System :: Distributed Computing
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: asyncpg
Requires-Dist: pydantic>=2.0.0
Provides-Extra: dev
Requires-Dist: asyncpg; extra == "dev"
Requires-Dist: asyncpg-stubs; extra == "dev"
Requires-Dist: mypy-extensions; extra == "dev"
Requires-Dist: mypy; extra == "dev"
Requires-Dist: pytest-asyncio; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: ruff; extra == "dev"
Provides-Extra: docs
Requires-Dist: myst-parser; extra == "docs"
Requires-Dist: sphinx; extra == "docs"
Requires-Dist: sphinx-rtd-theme; extra == "docs"

# **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:

```bash
pip install notifelect
python -m notifelect install  # Set up necessary database sequences
```

## Quick Example
Simulate a leader election among N processes:

```python
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.
