PyMySQLLock
MySQL Backed Locking Primitive
What it is and what it does
PyMySQLLock wraps MySQL's GET_LOCK function to provide a simple distributed locking mechanism for coordinating work across multiple Python application instances that share a common MySQL database. Instead of adding external systems like Zookeeper or etcd, it leverages your existing MySQL infrastructure to ensure only one instance holds a lock at a time and can execute protected tasks.
The package exposes a Locker class that takes standard MySQL connection parameters, then creates named Lock objects that can be acquired with optional timeouts and released when done. It maintains the lock by periodically pinging the MySQL connection in the background to prevent idle disconnection. You can also query all currently held locks on the database.
Use it for:
- Coordinate scheduled job execution across multiple application servers so only one instance runs a critical task at a time.
- Prevent race conditions when multiple instances need exclusive access to a shared resource managed through MySQL.
- Implement leader election or primary-replica coordination in a cluster without deploying additional infrastructure.
- Serialize access to database operations that cannot tolerate concurrent modification from multiple application instances.
- Gate one-time initialization or migration tasks that should run exactly once across a fleet of servers.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides distributed locking primitives backed by MySQL's GET_LOCK function, allowing multiple application instances to coordinate exclusive access to named resources through a shared MySQL database.
No. The package is abandoned (last release 2020-09-13, no maintenance since) and classified as pre-alpha. While the concept is sound and the MIT license is permissive, the lack of updates means no fixes for bugs, compatibility issues with modern Python or MySQL versions, or security concerns. Consider a maintained alternative like a Redis-based lock library or a purpose-built distributed coordination tool unless you have a very stable, isolated deployment and can accept the risk of no future support.
Install
pymysqllock on PyPI
pip
pip install pymysqllockuv
uv add pymysqllockpoetry
poetry add pymysqllockInstalling PyMySQLLock
Before you install
Installation is straightforward with no runtime dependencies. However, the package is abandoned—last release was 2020-09-13 with no commits or maintenance signals since. Use only if you accept the risk of unpatched issues and no future updates.
License in practice
MIT license permits commercial and private use with minimal restrictions, requiring only license and copyright notice retention.
Quickstart
pip install PyMySQLLock
from PyMySQLLock import Locker
locker = Locker(host="localhost", user="root", password="password", database="db")
lock = locker.lock("lock_name")
lock.acquire(timeout=10)
# do something
lock.release()
Requires an active MySQL connection; the package works with PyMYSQL, mysql-connector-python, or mysqlclient but does not include or install any MySQL driver itself.
Verify before relying
- Whether the package works reliably with modern MySQL versions and current Python 3.9+ releases beyond the declared support for 3.6–3.8.
- Whether background connection refresh (ping interval) is sufficient to prevent connection timeouts in production environments.
- Performance characteristics and scalability limits when many application instances contend for locks on a single MySQL database.
Package facts
| License | MIT license (permissive) |
| Python support | supports the current Python release (>=3.5) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | abandoned — 2,161 days since the last release |
| First released | |
| Downloads | 255,021/month — #8,485 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: PyMySQLLock-0.2.0-py2.py3-none-any.whl
Keywords: PyMySQLLock
Tags
More Database packages
psycopg2-binary is a PostgreSQL database…
copyleft · top 1,000 on PyPI
redisPython client library for connecting to and…
permissive · top 1,000 on PyPI
ydbYDB Python SDK is the official client library…
permissive · top 1,000 on PyPI
snowflake-connector-pythonConnects Python applications to Snowflake data…
permissive · top 1,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
dbt-adaptersProvides base adapter protocols and shared…
permissive · top 1,000 on PyPI
python-dynamodb-lockProvides distributed locking on top of DynamoDB…
permissive · top 15,000 on PyPI
redlock-pyImplements Redis-based distributed locks using…
permissive · top 15,000 on PyPI
python-redis-lockProvides a Redis-backed distributed lock with a…
permissive · top 5,000 on PyPI
aiorwlockProvides read-write locks for asyncio programs,…
permissive · top 5,000 on PyPI
redlockImplements the RedLock algorithm to provide…
permissive · top 15,000 on PyPI
locketLocket provides file-based locks for…
permissive · top 1,000 on PyPI
zc.lockfileProvides portable inter-process locks…
unclear · top 5,000 on PyPI
etcd-sdk-pythonPython client for etcd v3 API that provides…
permissive · top 15,000 on PyPI
django-pglockProvides Postgres advisory locks, table locks,…
permissive · top 5,000 on PyPI
django-pglocksProvides PostgreSQL advisory locks for Django…
permissive · top 15,000 on PyPI