{"library":"python-dynamodb-lock","title":"Python DynamoDB Lock","description":"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.","language":"python","status":"maintenance","last_verified":"Sat May 16","install":{"commands":["pip install python-dynamodb-lock"],"cli":null},"imports":["from python_dynamodb_lock import DynamoDBLockClient"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import boto3\nfrom python_dynamodb_lock import DynamoDBLockClient\nimport os\nimport time\n\n# Configure AWS credentials and region (e.g., via environment variables or ~/.aws/credentials)\n# For local testing, you might use 'local' endpoint_url\ndynamodb_resource = boto3.resource(\n    'dynamodb',\n    region_name=os.environ.get('AWS_REGION', 'us-east-1'),\n    endpoint_url=os.environ.get('DYNAMODB_ENDPOINT_URL', None)\n)\n\ntable_name = os.environ.get('DYNAMODB_LOCK_TABLE_NAME', 'MyDistributedLockTable')\n\n# It's recommended to create the table beforehand with a 'lock_key' primary key and TTL enabled\n# For demonstration, we'll try to create it if it doesn't exist\ntry:\n    table = dynamodb_resource.Table(table_name)\n    table.load()\nexcept dynamodb_resource.meta.client.exceptions.ResourceNotFoundException:\n    print(f\"Creating DynamoDB table: {table_name}\")\n    dynamodb_resource.create_table(\n        TableName=table_name,\n        KeySchema=[{'AttributeName': 'lock_key', 'KeyType': 'HASH'}],\n        AttributeDefinitions=[{'AttributeName': 'lock_key', 'AttributeType': 'S'}],\n        BillingMode='PAY_PER_REQUEST'\n    )\n    # Wait for the table to be active\n    dynamodb_resource.meta.client.get_waiter('table_exists').wait(TableName=table_name)\n    print(f\"Table {table_name} created.\")\n\n# Instantiate the lock client\n# The 'owner_name' helps identify who holds the lock (e.g., hostname + process ID)\nlock_client = DynamoDBLockClient(\n    dynamodb_resource,\n    table_name=table_name,\n    owner_name=f\"{os.uname()[1]}-{os.getpid()}\"\n)\n\nlock_key = \"my-critical-resource\"\n\ntry:\n    print(f\"Attempting to acquire lock for {lock_key}...\")\n    # Use the 'lock' method as a context manager for a specific lock\n    with lock_client.lock(lock_key):\n        print(f\"Successfully acquired lock for {lock_key}. Performing critical section...\")\n        # Simulate work\n        time.sleep(5)\n        print(f\"Finished critical section for {lock_key}.\")\n    print(f\"Lock for {lock_key} automatically released.\")\nexcept Exception as e:\n    print(f\"Failed to acquire or process with lock for {lock_key}: {e}\")\nfinally:\n    # It's important to close the client to stop background heartbeat threads\n    print(\"Closing lock client...\")\n    lock_client.close() \n    print(\"Lock client closed.\")","lang":"python","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-16","installed_version":"0.9.1","pypi_latest":"0.9.1","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":3.8,"avg_import_s":null,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"python-dynamodb-lock","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"50.7M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"python-dynamodb-lock","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":4.2,"import_time_s":null,"mem_mb":null,"disk_size":"51M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"python-dynamodb-lock","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"53.7M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"python-dynamodb-lock","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":3.8,"import_time_s":null,"mem_mb":null,"disk_size":"54M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"python-dynamodb-lock","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"45.3M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"python-dynamodb-lock","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":3.3,"import_time_s":null,"mem_mb":null,"disk_size":"46M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"python-dynamodb-lock","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"45.0M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"python-dynamodb-lock","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":3.1,"import_time_s":null,"mem_mb":null,"disk_size":"46M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"python-dynamodb-lock","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"50.1M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"python-dynamodb-lock","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":4.5,"import_time_s":null,"mem_mb":null,"disk_size":"51M"}]}}