Skip to main content

py-mysql-lock

MySQL Backed Locking Primitive

https://img.shields.io/pypi/v/py-mysql-lock.svg https://api.travis-ci.com/sanketplus/py-mysql-lock.svg Coverage! Documentation Status

py-mysql-lock provides locking primitive based on MySQL’s GET_LOCK

Use Cases

Though there are mature locking primitives provided by systems like Zookeeper and etcd, when you have an application which is primarily dependent on MySQL for its uptime and health, added resiliency provided by systems just mentioned doesn’t add much benefit. py-mysql-lock helps when you have multiple application instances which are backed by a common mysql instance and you want only one of those application instances to hold a lock and do certain tasks.

Documentation: https://py-mysql-lock.readthedocs.io

Installation

py-mysql-lock can be installed from pip. Alternate installation methods can be found in installation documentation

pip install PyMySQLLock

Usage

py-mysql-lock works with existing python mysql libraries like PyMYSQL, mysql-connector-python amd mysqlclient.

Getting A Named Lock

Getting a named lock is a three step process. First you will create a Locker instance. Argument to locker are the same arguments that you give to your MySQL library’s connect method. Locker then can be used to create Locks. Locks can be acquired and released.

from PyMySQLLock import Locker

locker = Locker(host="localhost", user="root",
                password="password", database="db")
lock = locker.lock("lock_name")

lock.acquire()  # returns True if lock is acquired

# do something

lock.release()

Timeout For Acquisition

Call to a lock’s acquire method takes an optional timeout arguments. The value is timeout in seconds. Default value is -1 which denotes wait for indefinite time.

# wait for 10 seconds. If lock is not acquired, False is returned
lock.acquire(timeout=10)

TODO

  • complete TODOs in code

  • Expand readme with examples and features

  • pypi publish

  • refresh lock

  • metadata api to get all locks in use

  • context manager

  • video demo

  • mark this project ready for review

Credits: This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

History

0.0.1 (2020-09-12)

  • First release on PyPI.

Metadata

Release files for PyMySQLLock 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyMySQLLock 0.0.1
File Size Uploaded Provenance Actions
PyMySQLLock-0.0.1.tar.gz 15.7 kB Without provenance Details for PyMySQLLock-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for PyMySQLLock 0.0.1
File Interpreter ABI Platform Actions
PyMySQLLock-0.0.1-py2.py3-none-any.whl Python 2, Python 3 none any Details for PyMySQLLock-0.0.1-py2.py3-none-any.whl

Total release size: 21.6 kB

Release files / PyMySQLLock-0.0.1.tar.gz

Download URL PyMySQLLock-0.0.1.tar.gz
Size 15.7 kB
Tags Source
SHA-256 checksum
How to use checksums
96e44295c6bc37f0993ab889f7fbc3b52a47999fe7b921ff77914a88d39e2651
BLAKE2b-256 checksum
How to use checksums
619308b2e3deac6a891dc39414702bac8aa334d9658c63da24e008130b16ceaa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.7

Release files / PyMySQLLock-0.0.1-py2.py3-none-any.whl

Download URL PyMySQLLock-0.0.1-py2.py3-none-any.whl
Size 5.8 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
41b43ba57024310d861465003dcd35e7b4df86a9a8d82cafa71264e1a29d1609
BLAKE2b-256 checksum
How to use checksums
c9bbfc802cfea7ed8d2ddc74b8c6e1a73280e6ccb8f9db5238f9a2609f0f01a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.7

Security for PyMySQLLock 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page