MongoElector
Distributed leader election and locking using MongoDB.
Components
- MongoLocker - Standalone distributed lock primitive backed by MongoDB with TTL-based expiration
- MongoLeaderElector - Leader election coordinator built on MongoLocker with background polling and callbacks
Installation
pip install mongoelector
Quick Start
Distributed Lock
from pymongo import MongoClient
from mongoelector import MongoLocker
db = MongoClient().my_database
lock = MongoLocker("my-resource", db, ttl=30)
lock.acquire()
try:
# do work while holding the lock
pass
finally:
lock.release()
Leader Election
from pymongo import MongoClient
from mongoelector import MongoLeaderElector
db = MongoClient().my_database
def became_leader():
print("I am the leader now")
def lost_leadership():
print("No longer the leader")
elector = MongoLeaderElector(
"my-service",
db,
ttl=15,
on_leader=became_leader,
on_leader_loss=lost_leadership,
)
elector.start()
Requirements
- Python >= 3.10
- pymongo >= 4.13
License
Apache 2.0
Release files for mongoelector 1.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mongoelector-1.0.2.tar.gz | 12.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mongoelector-1.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.7 kB
Release files / mongoelector-1.0.2.tar.gz
| Download URL | mongoelector-1.0.2.tar.gz |
|---|---|
| Size | 12.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fdd964aa6ad73c1c936bac46ca02c1286837f5d8c22fc92f2440850bcd181e7a
|
|
BLAKE2b-256 checksum How to use checksums |
0b6f728211bc6225b27f3eb4f8fa304ca7bd1f3de6d5132161c9f50cac6fc5ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 16, 2026.
Transparency logRelease files / mongoelector-1.0.2-py3-none-any.whl
| Download URL | mongoelector-1.0.2-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c0158eeeb3889784a49337eecb8eed8ed73e5723bad16c8c94491bf754f9502b
|
|
BLAKE2b-256 checksum How to use checksums |
73b44ba297d70c32dc14d74a6f313b319a60c19ab3410c1b8289ac793727e390
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 16, 2026.
Transparency log