Skip to main content

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())

Metadata

Release files for nats-kv-lock 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nats-kv-lock 0.0.1
File Size Uploaded Provenance Actions
nats_kv_lock-0.0.1.tar.gz 5.6 kB With provenance Details for nats_kv_lock-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nats-kv-lock 0.0.1
File Interpreter ABI Platform Actions
nats_kv_lock-0.0.1-py3-none-any.whl Python 3 none any Details for nats_kv_lock-0.0.1-py3-none-any.whl

Total release size: 9.4 kB

Release files / nats_kv_lock-0.0.1.tar.gz

Download URL nats_kv_lock-0.0.1.tar.gz
Size 5.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2e8bcf7629fbfc4805893e6901223fffcad2da6c4dd62ad4022a2f914b6637c2
BLAKE2b-256 checksum
How to use checksums
ca0ddfcbd3ffc3d71f15e79f0108a0d9950b3758e59e379160ad7b50fb6f6671
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Jul 17, 2025.

Transparency log

Release files / nats_kv_lock-0.0.1-py3-none-any.whl

Download URL nats_kv_lock-0.0.1-py3-none-any.whl
Size 3.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bad2c86ee6aa3208d3a67e5c4b26b9d924b0387c44655a95bb822dfda083caba
BLAKE2b-256 checksum
How to use checksums
13783e977313128d21a979ad4d15d47e4bbb2e31684cc14a0d7f8738028d8287
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Jul 17, 2025.

Transparency log

Security for nats-kv-lock 0.0.1

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for nats_kv_lock-0.0.1.tar.gz

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 Jul 17, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page