Skip to main content

Python client SDK for lockserver (distributed lock server)

Project description

Publishing to PyPI

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:

  1. Make sure you have build and twine installed:
    pip install --upgrade build twine
    
  2. Build the package:
    python3 -m build
    
  3. Upload to PyPI:
    python3 -m twine upload dist/*
    
  4. Check your package at https://pypi.org/project/lockserver-client/

If you update the README, rebuild and re-upload to update the PyPI description.

lockserver-client (Python)

A Python client SDK for lockserver, a distributed lock server for coordinating access to shared resources.

Install

pip install requests

Usage

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

Example: Multiple workers writing to S3

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

API

LockserverClient(addr=None, owner=None, secret=None)

  • addr: lockserver address (default: 127.0.0.1:8080)
  • owner: unique owner id (default: default_owner)
  • secret: shared secret (default: changeme)

acquire(resource, blocking=True, expire=None)

  • Acquires a lock on resource. If blocking is 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) or False (non-blocking, lock not acquired).

release(resource)

  • Releases the lock on resource.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lockserver_client-0.1.3.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lockserver_client-0.1.3-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

Details for the file lockserver_client-0.1.3.tar.gz.

File metadata

  • Download URL: lockserver_client-0.1.3.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for lockserver_client-0.1.3.tar.gz
Algorithm Hash digest
SHA256 fe3e991673f4a406cba7d79a259db2e0a87f3b18e4a47f83a9e73e3016fda4b3
MD5 5ac09bcfaf244f014ab0f52edab73373
BLAKE2b-256 257f1c5fd4ae70fa4fb4a89882c56dfd91968b0c8d216ae0611d591ecc675a15

See more details on using hashes here.

File details

Details for the file lockserver_client-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for lockserver_client-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b949b18916d22491b32cb0643d2b82c1be6a78309e18e570ed78af6f0200636f
MD5 84993aa7ad05f3ecbdc8b9377cb6fb5c
BLAKE2b-256 9974c6c4c6b1c132c158b63b170e70a497f135dbc2f4bd79e55115a6bad4ab1c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page