skillfed

PyMySQLLock

MySQL Backed Locking Primitive

pymysqllock v0.2.0 255.0K downloads/30d#8,485 on PyPI
Permissive license MIT license Abandoned released

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 pymysqllock

uv

uv add pymysqllock

poetry

poetry add pymysqllock

Installing 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

Development Status :: 2 - Pre-AlphaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseNatural Language :: EnglishProgramming Language :: Python :: 3Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8

Tags

mysql distributed lockmysql-based lockingmysql named lockmysql coordination primitivemysql mutual exclusionmysql lock acquire releasemysql shared resource lock
distributed-lockingmysql-coordinationabandoned

More Database packages