python-redis-lock
Lock context manager implemented via redis SETNX/BLPOP.
Decision gist · record as of 2026-08-14
Yes. This is a mature, actively maintained library (last release 128 days ago) with a simple, well-understood interface, zero security issues, and low install friction. Use it when you need cross-process locking backed by Redis and want to avoid spinloops or polling. The only prerequisite is a running Redis server.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires a running Redis server (2.6.12 or later) accessible via the redis connection object.
- Low friction: pure Python wheel with a single runtime dependency (redis).
- Actively maintained with recent release (128 days ago), 570 repository stars, and no known vulnerabilities.
License · maintenance · safety
BSD-2-Clause (permissive) — BSD-2-Clause is permissive; you may use, modify, and distribute this package freely in commercial and open-source projects with minimal restrictions.
last release 2026-04-08 (128 days) · last repo commit 2026-04-08 · 570 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 1,152,958 downloads/mo, #4,294 on PyPI
Alternatives
Verify before relying
from redis import Redis
import python_redis_lock
conn = Redis()
lock = python_redis_lock.Lock(conn, "my-lock")
if lock.acquire(blocking=False):
print("Got the lock")
lock.release()
# Or as context manager:
with python_redis_lock.Lock(conn, "my-lock"):
print("Lock held during this block")- Whether auto_renewal thread overhead is acceptable for your workload and latency requirements.
- Performance characteristics under high contention or with many lock holders across processes.
- Exact behavior and guarantees of the SETNX/BLPOP implementation under network partitions.
What it is and what it does
python-redis-lock is a distributed locking library that uses Redis to coordinate access to shared resources across multiple processes or machines. It implements a Lock class with an interface matching Python's threading.Lock, so it integrates naturally into existing code patterns. The lock uses Redis SETNX for acquisition and BLPOP for efficient waiting, avoiding spinloops and polling.
The package supports optional expiry (to recover from crashes), auto-renewal (to keep a lock active while your code runs), timeouts, and owner identification (to detect which process or machine holds a lock). It works with redis and includes a Django cache backend integration for preventing cache-stampede problems. Maintenance is active, Python 3.7 or later is supported, and there are no known security vulnerabilities.
Use it for
- Prevent multiple application instances from running the same scheduled task simultaneously in a distributed system.
- Coordinate database migrations or schema changes across a cluster without conflicts.
- Implement cache-stampede prevention in Django by locking cache misses so only one request recomputes expensive data.
- Protect critical sections in microservices that share state via Redis.
- Recover from application crashes by setting an expiry on locks so they auto-release after a timeout.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
This is a mature, actively maintained library (last release 128 days ago) with a simple, well-understood interface, zero security issues, and low install friction. Use it when you need cross-process locking backed by Redis and want to avoid spinloops or polling. The only prerequisite is a running Redis server.
Install
python-redis-lock on PyPI
Before you install
Low friction: pure Python wheel with a single runtime dependency (redis). Actively maintained with recent release (128 days ago), 570 repository stars, and no known vulnerabilities.
Requires a running Redis server (2.6.12 or later) accessible via the redis connection object.
License in practice
BSD-2-Clause is permissive; you may use, modify, and distribute this package freely in commercial and open-source projects with minimal restrictions.
Quickstart
from redis import Redis
import python_redis_lock
conn = Redis()
lock = python_redis_lock.Lock(conn, "my-lock")
if lock.acquire(blocking=False):
print("Got the lock")
lock.release()
# Or as context manager:
with python_redis_lock.Lock(conn, "my-lock"):
print("Lock held during this block")
Verify before relying
- Whether auto_renewal thread overhead is acceptable for your workload and latency requirements.
- Performance characteristics under high contention or with many lock holders across processes.
- Exact behavior and guarantees of the SETNX/BLPOP implementation under network partitions.
Package facts
| License | BSD-2-Clause permissive |
| Python support | Supports the current Python release >=3.7 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 1 packageredis |
| Maintenance | Actively maintained 128 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,152,958 / month, #4,294 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableIntended Audience :: DevelopersOperating System :: Microsoft :: WindowsOperating System :: POSIXOperating System :: UnixProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Utilities |
Evidence: python_redis_lock-4.0.1-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “redis distributed lock”
- python-redis-lockProvides a Redis-backed distributed lock with a threading.Lock-like…
- aioredlockImplements the Redlock distributed lock algorithm for asyncio,…
- redlock-pyImplements Redis-based distributed locks using the Redlock algorithm,…
Give your agent the search over MCP, or paste the wish link into any chat.
More Utilities packages
Converts domain names between Unicode and ASCII-compatible encoding (Punycode) according to IDNA 2008 and Unicode Technical Standard 46, with security validation and broader script coverage than the standard library.
Install it if you work with internationalized domain names, need to validate domains, or use HTTP clients that depend on it transitively.
Detects and normalizes text encoding from unknown or ambiguous sources, supporting all IANA character sets that Python's core library provides codecs for, with the ability to register custom codecs.
Setuptools is a Python build backend and package management tool that handles building, distributing, and installing Python packages, including support for C/C++ extension modules.
Pluggy provides a plugin system that lets you define hook specifications and register implementations to be called in sequence, enabling extensible Python applications without tight coupling.
Install it if you're building an extensible application or framework.
Pygments is a syntax highlighter that colorizes source code and text in over 500 languages and formats, outputting to HTML, LaTeX, RTF, SVG, images, or ANSI terminal sequences.
Install it if you need to display or transform source code.
Six provides utility functions to write Python code that runs on both Python 2.7 and Python 3.3+, smoothing over language differences between the two versions.
See also pottery · redlock · redlock-py · aioredlock · PyMySQLLock · python-dynamodb-lock · portalocker · aiorwlock · celery_once · celery-singleton