Distributed lock using NATS.io
Project description
nats-kv-lock
A simple, distributed lock using NATS.io
Note!
- This is a simple PoC and perhaps shouldn't be used in a production environment
- This does NOT guarantee order, i.e. it is an unfair lock.
Installation
Assuming you already have NATS installed, you can simply pip install nats-kv-lock
Example
All you need to do is create a KV bucket, then initialize an instance of NatsKvLock using that bucket with a shared lock_name.
import asyncio
from nats import connect
from nats_kv_lock import NatsKvLock
async def main():
print('connecting...')
nc = await connect()
print('connected!')
js = nc.jetstream()
try:
kv = await js.key_value(bucket='my_locks')
except:
kv = await js.create_key_value(bucket='my_locks')
my_lock = NatsKvLock(kv, 'my_lock')
print('acquiring lock...')
async with my_lock:
print('acquired! doing work...')
await asyncio.sleep(10)
print('releasing lock...')
print('released lock!')
if __name__ == '__main__':
asyncio.run(main())
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 nats_kv_lock-0.0.1.tar.gz.
File metadata
- Download URL: nats_kv_lock-0.0.1.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e8bcf7629fbfc4805893e6901223fffcad2da6c4dd62ad4022a2f914b6637c2
|
|
| MD5 |
d0ff355e408e432e5b0348eb3a8af40c
|
|
| BLAKE2b-256 |
ca0ddfcbd3ffc3d71f15e79f0108a0d9950b3758e59e379160ad7b50fb6f6671
|
Provenance
The following attestation bundles were made for nats_kv_lock-0.0.1.tar.gz:
Publisher:
python-publish.yml on kevinhikaruevans/nats-kv-lock
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nats_kv_lock-0.0.1.tar.gz -
Subject digest:
2e8bcf7629fbfc4805893e6901223fffcad2da6c4dd62ad4022a2f914b6637c2 - Sigstore transparency entry: 282283403
- Sigstore integration time:
-
Permalink:
kevinhikaruevans/nats-kv-lock@43ba3e470981e7f62c1eae07de227eed5a74de73 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/kevinhikaruevans
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@43ba3e470981e7f62c1eae07de227eed5a74de73 -
Trigger Event:
release
-
Statement type:
File details
Details for the file nats_kv_lock-0.0.1-py3-none-any.whl.
File metadata
- Download URL: nats_kv_lock-0.0.1-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bad2c86ee6aa3208d3a67e5c4b26b9d924b0387c44655a95bb822dfda083caba
|
|
| MD5 |
5be78e048b4c0e52b08d387136c68004
|
|
| BLAKE2b-256 |
13783e977313128d21a979ad4d15d47e4bbb2e31684cc14a0d7f8738028d8287
|
Provenance
The following attestation bundles were made for nats_kv_lock-0.0.1-py3-none-any.whl:
Publisher:
python-publish.yml on kevinhikaruevans/nats-kv-lock
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nats_kv_lock-0.0.1-py3-none-any.whl -
Subject digest:
bad2c86ee6aa3208d3a67e5c4b26b9d924b0387c44655a95bb822dfda083caba - Sigstore transparency entry: 282283446
- Sigstore integration time:
-
Permalink:
kevinhikaruevans/nats-kv-lock@43ba3e470981e7f62c1eae07de227eed5a74de73 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/kevinhikaruevans
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@43ba3e470981e7f62c1eae07de227eed5a74de73 -
Trigger Event:
release
-
Statement type: