Distributed leader election and locking using MongoDB
Project description
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
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mongoelector-1.0.2.tar.gz.
File metadata
- Download URL: mongoelector-1.0.2.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fdd964aa6ad73c1c936bac46ca02c1286837f5d8c22fc92f2440850bcd181e7a
|
|
| MD5 |
88c772c3ee2fb156b9e019c9af9005b4
|
|
| BLAKE2b-256 |
0b6f728211bc6225b27f3eb4f8fa304ca7bd1f3de6d5132161c9f50cac6fc5ec
|
Provenance
The following attestation bundles were made for mongoelector-1.0.2.tar.gz:
Publisher:
workflow.yml on zebpalmer/MongoElector
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mongoelector-1.0.2.tar.gz -
Subject digest:
fdd964aa6ad73c1c936bac46ca02c1286837f5d8c22fc92f2440850bcd181e7a - Sigstore transparency entry: 954393628
- Sigstore integration time:
-
Permalink:
zebpalmer/MongoElector@5c411218b561589468a09bf3c62f3f93a1b7f0b4 -
Branch / Tag:
refs/tags/1.0.2 - Owner: https://github.com/zebpalmer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@5c411218b561589468a09bf3c62f3f93a1b7f0b4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mongoelector-1.0.2-py3-none-any.whl.
File metadata
- Download URL: mongoelector-1.0.2-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0158eeeb3889784a49337eecb8eed8ed73e5723bad16c8c94491bf754f9502b
|
|
| MD5 |
d2c3e034d213a2977dcb19e9ead17064
|
|
| BLAKE2b-256 |
73b44ba297d70c32dc14d74a6f313b319a60c19ab3410c1b8289ac793727e390
|
Provenance
The following attestation bundles were made for mongoelector-1.0.2-py3-none-any.whl:
Publisher:
workflow.yml on zebpalmer/MongoElector
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mongoelector-1.0.2-py3-none-any.whl -
Subject digest:
c0158eeeb3889784a49337eecb8eed8ed73e5723bad16c8c94491bf754f9502b - Sigstore transparency entry: 954393629
- Sigstore integration time:
-
Permalink:
zebpalmer/MongoElector@5c411218b561589468a09bf3c62f3f93a1b7f0b4 -
Branch / Tag:
refs/tags/1.0.2 - Owner: https://github.com/zebpalmer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@5c411218b561589468a09bf3c62f3f93a1b7f0b4 -
Trigger Event:
push
-
Statement type: