django-dbconn-retry
Patch Django to retry a database connection first before failing.
What it is and what it does
django-dbconn-retry patches Django's database wrapper to handle closed TCP connections gracefully. When a database operation fails because the connection was already closed—a common issue when using load balancers like HAProxy or connection poolers like pgbouncer—the library automatically attempts to reconnect and retry the operation instead of immediately raising an OperationalError.
The package is configured via Django settings (MAX_DBCONN_RETRY_TIMES, DBCONN_RETRY_DELAY, DBCONN_RETRY_BACKOFF) and exposes Django Signals (pre_reconnect, post_reconnect) to allow other code to hook into the reconnection process. This is useful for scenarios like refreshing database credentials from Hashicorp Vault before reconnecting, or handling credential expiration in dynamic authentication systems.
Use it for:
- Recover from transient connection drops caused by HAProxy or pgbouncer load balancers without raising exceptions to the application.
- Automatically refresh database credentials from Hashicorp Vault when a connection fails due to expired credentials.
- Reduce application crashes and improve resilience in environments with aggressive connection timeout policies.
- Implement graceful retry logic for database operations in microservices architectures with unstable network conditions.
- Handle connection state mismatches in high-availability database setups without explicit application-level retry code.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Automatically reconnects Django database connections when the underlying TCP connection has been closed, retrying the failed operation instead of immediately raising an OperationalError.
Yes, if you run Django with load-balanced or pooled database connections (HAProxy, pgbouncer, Vault). The package solves a real operational problem with low friction and no dependencies. No known vulnerabilities. Active maintenance and permissive license. Not necessary if your database connections are stable and direct.
Install
django-dbconn-retry on PyPI
pip
pip install django-dbconn-retryuv
uv add django-dbconn-retrypoetry
poetry add django-dbconn-retryInstalling django-dbconn-retry
Before you install
Low install friction with no runtime dependencies. Active maintenance as of 2026-05-02, with recent repository activity (last commit 2026-08-10). Moderate popularity at top_15000 tier with ~92140 monthly downloads.
License in practice
BSD License (permissive). Allows commercial use, modification, and distribution with minimal restrictions—only requires retaining copyright notice and disclaimer.
Quickstart
pip install django-dbconn-retry
# In settings.py, add to INSTALLED_APPS:
INSTALLED_APPS = [
'django_dbconn_retry',
# ...
]
# Optional: configure retry behavior
MAX_DBCONN_RETRY_TIMES = 1 # default
DBCONN_RETRY_DELAY = 0 # default
DBCONN_RETRY_BACKOFF = 1 # default
Verify before relying
- Whether the package works with all Django versions or has specific version constraints not listed in the fact sheet.
- Whether the monkeypatch approach has any known incompatibilities with other Django middleware or database backends.
- Performance impact of the retry mechanism under high-concurrency workloads.
Package facts
| License | not declared (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 104 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 92,140/month — #13,474 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_dbconn_retry-0.3.1-py3-none-any.whl
Tags
More Database packages
psycopg2-binary is a PostgreSQL database…
copyleft · top 1,000 on PyPI
redisPython client library for connecting to and…
permissive · top 1,000 on PyPI
ydbYDB Python SDK is the official client library…
permissive · top 1,000 on PyPI
snowflake-connector-pythonConnects Python applications to Snowflake data…
permissive · top 1,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
dbt-adaptersProvides base adapter protocols and shared…
permissive · top 1,000 on PyPI
reretryA decorator and function wrapper for retrying…
permissive · top 15,000 on PyPI
retryProvides a decorator and function wrapper for…
permissive · top 1,000 on PyPI
retryingRetrying is a decorator-based library that adds…
permissive · top 1,000 on PyPI
waiterWaiter provides iteration-based retry and…
permissive · top 15,000 on PyPI
retry2Provides a decorator and function wrapper to…
permissive · top 5,000 on PyPI
pyramid-retrypyramid_retry wraps Pyramid requests with…
permissive · top 15,000 on PyPI
django-db-connection-poolProvides connection pooling for Django database…
permissive · top 15,000 on PyPI
django-valkeyProvides a Valkey cache and session backend for…
permissive · top 15,000 on PyPI
bleak-retry-connectorWraps Bleak's Bluetooth client with automatic…
permissive · top 5,000 on PyPI
retry-requestsWraps requests Session objects to automatically…
copyleft · top 15,000 on PyPI