Python DynamoDB Lock is a general-purpose distributed locking library built on top of DynamoDB. It supports both coarse-grained and fine-grained locking, heavily inspired by the Java-based AmazonDynamoDBLockClient. The current version is 0.9.1, with the last release in October 2018. While functional, its development appears to be in maintenance mode.
pip install python-dynamodb-lockVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to acquire and release a distributed lock using `DynamoDBLockClient` as a context manager for a specific resource. It includes basic setup for a DynamoDB table and shows how to handle the critical section.
Evaluate against modern alternatives or consider contributing to the project if extended functionality or maintenance is required.
Design your application with eventual consistency in mind or implement application-level checks to handle potential conflicts if a lock is stolen. Do not assume transactional guarantees across lock acquisition and business logic.
Ensure your DynamoDB table has a TTL attribute configured (default: 'expiry_time') and that `expiry_period` is set appropriately during client instantiation to allow timely cleanup of abandoned locks. Implement robust error handling and graceful shutdown procedures where possible.
Explicitly manage lock release for individual `DynamoDBLock` instances. If you need to force release all locks on shutdown, you might need to iterate through and release them, or rely on TTL for cleanup (see previous warning).
Before using the library, ensure your DynamoDB table adheres to the required schema and has TTL enabled. Example table creation is provided in the quickstart.