This is a Python (3.7+) client library for https://distributed-lock.com SAAS.
It's not a CLI (just a library). If you are looking for a good CLI binary, have a look at our golang client.
- asyncio support
- observability API
pip install distributed-lock-client
from distributed_lock_client import DistributedLockClient
# assert DLOCK_TOKEN env var defined with your API token
# assert DLOCK_TENANT_ID env var defined with your "tenant id"
# (you can also pass them to the DistributedLockClient
# constructor or you can also use DLOCK_CLUSTER env var)
with DistributedLockClient(cluster="europe-free").exclusive_lock(
"bar", lifetime=20, wait=10
):
# WE HAVE THE LOCK!
# [...] DOING SOME IMPORTANT THINGS [...]
pass
# THE LOCK IS RELEASED
You have 2 APIs:
- the (recommended) context manager API (like above)
- the low level API
For the low level API, the idea is the same:
- first, you create a
DistributedLockClient
object with some options (most of them can be set as env var) - second, you invoke on the object the method
acquire_exclusive_lock()
and/orrelease_exclusive_lock
Example (of the low level API):
from distributed_lock_client import DistributedLockClient
# assert DLOCK_TOKEN env var defined with your API token
# assert DLOCK_TENANT_ID env var defined with your "tenant id"
# (you can also pass them to the DistributedLockClient
# constructor or you can also use DLOCK_CLUSTER env var)
client = DistributedLockClient(cluster="europe-free")
# Acquire the resource "bar"
acquired_resource = client.acquire_exclusive_lock("bar", lifetime=20, wait=10)
lock_id = acquired_resource.lock_id
# WE HAVE THE LOCK!
# [...] DOING SOME IMPORTANT THINGS [...]
# Release the resource "bar"
client.release_exclusive_lock("bar", lock_id)
https://distributed-lock-com.github.io/python-client/
- managed by Poetry
- linting:
make lint
(inside a Poetry shell) - unit testing:
make test
(inside a Poetry shell) - api doc:
make apidoc
(inside a Poetry shell)