--- id: django-pglock version: "1.8.0" license: BSD-3-Clause license_treatment: permissive maintenance: aging --- # django-pglock — Postgres locking routines and lock table access. License: permissive · Maintenance: aging · Downloads: 1.4M/mo ## 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 above — verify before relying. Provides Postgres advisory locks, table locks, and lock management utilities for Django applications to prevent concurrent task execution and handle blocking locks. 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 pip install django-pglock uv add django-pglock poetry add django-pglock ## Installing django-pglock 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. 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 Requires Django 4.2–6.0, Postgres 14–18, and Psycopg 2–3. Must add 'pgactivity' and 'pglock' to Django's INSTALLED_APPS. 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_current - Install friction: low - Maintenance: aging - Downloads: 1.4M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags django postgres locking, advisory locks django, prevent concurrent tasks, postgres lock management, django database locking, task overlap prevention, blocking lock detection, postgres-locking, concurrency-control, django-extension [View on SkillFed](https://skillfed.io/packages/django-pglock) · [View on PyPI](https://pypi.org/project/django-pglock/)