django-pglock
Postgres locking routines and lock table access.
Decision gist · record as of 2026-08-14
Yes, if you use Django with Postgres and need application-level locking or lock management. The low install friction, permissive license, and zero known vulnerabilities make it safe to adopt. The aging maintenance status (257 days since last release) is a minor concern but not a blocker—the repository is active and the package is stable for current Django and Python versions.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Django 4.2–6.0, Postgres 14–18, and Psycopg 2–3.
- Must add 'pgactivity' and 'pglock' to Django's INSTALLED_APPS.
- Low install friction with a pure Python wheel.
License · maintenance · safety
BSD-3-Clause (permissive) — BSD-3-Clause is permissive; you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
last release 2025-11-30 (257 days) · last repo commit 2025-11-30 · 70 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 1,425,714 downloads/mo, #3,916 on PyPI
Alternatives
Verify before relying
pip install django-pglock
import pglock
with pglock.advisory("my_lock_id"):
# Code here runs exclusively, blocking until lock is available- Whether the aging maintenance status (257 days since last release) affects stability for new Django/Python versions.
- Real-world performance impact of lock acquisition under high concurrency.
- Whether django-pgactivity dependency introduces additional constraints or maintenance risk.
What it is and what it does
django-pglock wraps Postgres's native locking mechanisms (advisory locks and table locks) as Django utilities, letting you prevent concurrent execution of code sections and manage lock contention. It provides decorators and context managers for application-level synchronization—useful for ensuring background tasks don't overlap, locking entire models during transactions, and forcibly terminating blocking locks to prioritize critical code like migrations.
The package depends on django and django-pgactivity and exposes a management command for querying and killing locks from the CLI. It supports Python 3.10–3.14 and Django 4.2–6.0, with compatibility across Postgres 14–18 and both Psycopg 2 and 3.
Use it for
- Prevent duplicate execution of periodic background tasks or Celery jobs by wrapping them in advisory locks.
- Lock an entire model during a transaction to ensure exclusive access for critical data updates.
- Dynamically set Postgres lock timeouts to fail fast when lock acquisition takes too long.
- Terminate blocking locks from migrations or high-priority code to avoid deadlock situations.
- Query active and blocked locks via the PGLock and BlockedPGLock proxy models for monitoring.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you use Django with Postgres and need application-level locking or lock management.
The low install friction, permissive license, and zero known vulnerabilities make it safe to adopt. The aging maintenance status (257 days since last release) is a minor concern but not a blocker—the repository is active and the package is stable for current Django and Python versions.
Install
django-pglock on PyPI
Before you install
Low install friction with a pure Python wheel. Maintenance status is aging—last release was 257 days ago—but the repository remains active with recent commits and no archived status.
Requires Django 4.2–6.0, Postgres 14–18, and Psycopg 2–3. Must add 'pgactivity' and 'pglock' to Django's INSTALLED_APPS.
License in practice
BSD-3-Clause is permissive; you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install django-pglock
import pglock
with pglock.advisory("my_lock_id"):
# Code here runs exclusively, blocking until lock is available
Verify before relying
- Whether the aging maintenance status (257 days since last release) affects stability for new Django/Python versions.
- Real-world performance impact of lock acquisition under high concurrency.
- Whether django-pgactivity dependency introduces additional constraints or maintenance risk.
Package facts
| License | BSD-3-Clause permissive |
| Python support | Supports the current Python release <4,>=3.10.0 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 2 packagesdjangodjango-pgactivity |
| Maintenance | Aging 257 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,425,714 / month, #3,916 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Framework :: DjangoFramework :: Django :: 4.2Framework :: Django :: 5.0Framework :: Django :: 5.1Framework :: Django :: 5.2Framework :: Django :: 6.0Intended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming 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.14 |
Evidence: django_pglock-1.8.0-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 › “django postgres locking”
- django-pglockProvides Postgres advisory locks, table locks, and lock management…
- django-pgmigratePrevents migration downtime by detecting and terminating blocking…
- django-pglocksProvides PostgreSQL advisory locks for Django applications through…
Give your agent the search over MCP, or paste the wish link into any chat.
More Database packages
psycopg2-binary is a PostgreSQL database adapter for Python that implements the DB API 2.0 specification, enabling Python applications to connect to and query PostgreSQL databases with thread-safe concurrent operations.
Python client library for connecting to and executing commands against Redis key-value stores, supporting both synchronous and asynchronous operations.
Install it if your application needs to interact with Redis; the only prerequisite is a running Redis server instance.
YDB Python SDK is the official client library for connecting to and querying YDB databases from Python applications.
Install it if you need to connect Python applications to YDB databases.
Connects Python applications to Snowflake data warehouses using the DB API 2.0 specification, enabling SQL queries, data transfers, and warehouse operations.
sqlparse tokenizes SQL text into a tree of statements, clauses, and expressions, and provides functions to split scripts, format queries, and inspect parsed tokens without validating dialect or syntax.
Install it if you need to manipulate, format, or analyze SQL text programmatically.
Provides base adapter protocols and shared functionality that database adapters use to integrate with dbt-core, handling connections, dialect translation, relation caching, and core interface management.
See also django-concurrency · django-pgactivity · django-pglocks · django-pgmigrate · django-pg-zero-downtime-migrations · django-pg-migration-tools · PyMySQLLock · filelock · python-dynamodb-lock · celery_once