{"id":20959191,"url":"https://github.com/sanketplus/py-mysql-lock","last_synced_at":"2026-04-18T05:02:53.944Z","repository":{"id":94553067,"uuid":"294870703","full_name":"sanketplus/py-mysql-lock","owner":"sanketplus","description":"MySQL Backed Locking Primitive","archived":false,"fork":false,"pushed_at":"2020-09-13T14:03:29.000Z","size":45,"stargazers_count":3,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-31T22:45:05.228Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sanketplus.png","metadata":{"files":{"readme":"README.rst","changelog":"HISTORY.rst","contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-09-12T04:36:34.000Z","updated_at":"2023-03-04T11:08:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"ee836e14-9157-4a0b-8090-4a201c50acf4","html_url":"https://github.com/sanketplus/py-mysql-lock","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/sanketplus/py-mysql-lock","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanketplus%2Fpy-mysql-lock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanketplus%2Fpy-mysql-lock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanketplus%2Fpy-mysql-lock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanketplus%2Fpy-mysql-lock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sanketplus","download_url":"https://codeload.github.com/sanketplus/py-mysql-lock/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanketplus%2Fpy-mysql-lock/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31957158,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-18T00:39:45.007Z","status":"online","status_checked_at":"2026-04-18T02:00:07.018Z","response_time":103,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T01:52:09.713Z","updated_at":"2026-04-18T05:02:53.883Z","avatar_url":"https://github.com/sanketplus.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"=============\npy-mysql-lock\n=============\n\n------------------------------\nMySQL Backed Locking Primitive\n------------------------------\n\n.. image:: https://img.shields.io/pypi/v/PyMySQLLock.svg\n        :target: https://pypi.python.org/pypi/PyMySQLLock\n\n.. image:: https://api.travis-ci.com/sanketplus/py-mysql-lock.svg\n        :target: https://travis-ci.com/sanketplus/py-mysql-lock\n\n.. image:: https://codecov.io/github/sanketplus/py-mysql-lock/coverage.svg?branch=master\u0026precision=2\n        :target: https://codecov.io/gh/sanketplus/py-mysql-lock\n        :alt: Coverage!\n\n.. image:: https://readthedocs.org/projects/py-mysql-lock/badge/?version=latest\n        :target: https://Py-MySQL-Lock.readthedocs.io/en/latest/?badge=latest\n        :alt: Documentation Status\n\n\npy-mysql-lock provides locking primitive based on MySQL's GET_LOCK\n\n\nUse Cases\n---------\n\nThough 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.\n\n\n    Documentation: https://py-mysql-lock.readthedocs.io\n\n\nInstallation\n------------\n\npy-mysql-lock can be installed from pip. Alternate installation methods can be found in `installation documentation \u003chttps://py-mysql-lock.readthedocs.io/en/latest/installation.html\u003e`_\n::\n\n    pip install PyMySQLLock\n\n-----\nUsage\n-----\n\npy-mysql-lock works with existing python mysql libraries like PyMYSQL, mysql-connector-python amd mysqlclient.\n\nGetting A Named Lock\n--------------------\n\nGetting a named lock is a three step process. First you will create a ``Locker`` instance. Argument to locker are the\nsame arguments that you give to your MySQL library's ``connect`` method. Locker then can be used to create Locks. Locks\ncan be acquired and released.\n::\n\n    from PyMySQLLock import Locker\n\n    locker = Locker(host=\"localhost\", user=\"root\",\n                    password=\"password\", database=\"db\")\n    lock = locker.lock(\"lock_name\")\n\n    lock.acquire()  # returns True if lock is acquired\n\n    # do something\n\n    lock.release()\n\nTimeout For Acquisition\n-----------------------\n\nCall to a lock's ``acquire`` method takes an optional ``timeout`` arguments. The value is timeout\nin seconds. Default value is -1 which denotes wait for indefinite time.\n::\n\n    # wait for 10 seconds. If lock is not acquired, False is returned\n    lock.acquire(timeout=10)\n\nRefresh Interval\n-----------------------\n\nSince the lock is acquired on a mysql connection, it is important for the connection to stay alive. To prevent connection\nfrom breaking due to inactivity, py-mysql-lock keeps pinging on the connection in background. The default ping interval\nis 10 seconds and optionally can be set with ``acquire`` call,\n::\n\n    lock.acquire(timeout=10, refresh_interval_secs=1)\n\nGet All Locks\n-----------------------\n\nYou can also query the mysql database for getting all current acquired locks on the given db.\n::\n\n    locker.get_all_locks()  # returns list of names (string) of locks acquired on the db\n\n\n\n**Credits:** This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.\n\n.. _Cookiecutter: https://github.com/audreyr/cookiecutter\n.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanketplus%2Fpy-mysql-lock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsanketplus%2Fpy-mysql-lock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanketplus%2Fpy-mysql-lock/lists"}