This package is ready for PyPI. The setup.py uses your README.md as the long description, so your PyPI page will show this documentation.
To publish:
- Make sure you have
buildandtwineinstalled:pip install --upgrade build twine
- Build the package:
python3 -m build
- Upload to PyPI:
python3 -m twine upload dist/* - Check your package at https://pypi.org/project/lockserver-client/
If you update the README, rebuild and re-upload to update the PyPI description.
A Python client SDK for lockserver, a distributed lock server for coordinating access to shared resources.
pip install requests
from lockserver_client import LockserverClient
client = LockserverClient(
addr='127.0.0.1:8080', # or from env LOCKSERVER_ADDR
owner='worker1', # or from env LOCKSERVER_OWNER
secret='your-strong-secret' # or from env LOCKSERVER_SECRET
)
# Blocking acquire
client.acquire('my-resource')
# ... critical section ...
client.release('my-resource')
# Non-blocking acquire
if client.acquire('my-resource', blocking=False):
# ... critical section ...
client.release('my-resource')from lockserver_client import LockserverClient
def upload_to_s3(bucket, file):
print(f"Uploading {file} to {bucket}...")
client = LockserverClient(owner='worker-123', secret='your-strong-secret')
if client.acquire('s3-upload-lock'):
try:
upload_to_s3('my-bucket', 'file.txt')
finally:
client.release('s3-upload-lock')addr: lockserver address (default:127.0.0.1:8080)owner: unique owner id (default:default_owner)secret: shared secret (default:changeme)
- Acquires a lock on
resource. Ifblockingis False, returns immediately if lock is held. expire(optional): lock expiration in seconds. After this time, the lock is auto-released by the server.- Returns
True(lock acquired) orFalse(non-blocking, lock not acquired).
- Releases the lock on
resource.
MIT