django-db-geventpool
raw JSON → 4.0.8 verified Mon Apr 27 auth: no python
Provides a DB connection pool using gevent for Django, allowing concurrent database access in a gevent-ready manner. Current version 4.0.8, supports Django >= 4.2 and psycopg2/psycopg3. Release cadence is irregular.
pip install django-db-geventpool Common errors
error ModuleNotFoundError: No module named 'django_db_geventpool' ↓
cause Package not installed or virtual environment not activated.
fix
Run 'pip install django-db-geventpool' in your environment.
error django.core.exceptions.ImproperlyConfigured: 'django_db_geventpool.backends.postgresql_psycopg2' isn't an available database backend. ↓
cause Missing the required Django version or the package is not installed.
fix
Ensure django-db-geventpool is installed and Django >=4.2.
error AttributeError: module 'psycopg2' has no attribute 'extensions' ↓
cause gevent monkey-patching conflicts with psycopg2 when patched after psycopg2 is imported.
fix
Patch gevent BEFORE importing psycopg2 or Django. Move 'import gevent.monkey; gevent.monkey.patch_all()' to the top.
error OperationalError: FATAL: remaining connection slots are reserved for non-replication superuser connections ↓
cause Default pool size too large or connections not correctly recycled, exhausting PostgreSQL max_connections.
fix
Reduce pool size in DATABASES OPTIONS (e.g., 'MAX_CONNS': 10) and ensure connections are returned to pool (use context managers).
Warnings
breaking Version 4.0.0 dropped support for Django < 3.1. Version 4.0.8 drops support for Django < 4.2. Upgrade your Django version if you're on an older release. ↓
fix Upgrade Django to >=4.2, and use django-db-geventpool >=4.0.8.
gotcha You must call gevent.monkey.patch_all() before importing any Django modules, including settings. Otherwise, database connections will not be patched and may deadlock. ↓
fix Place 'import gevent.monkey; gevent.monkey.patch_all()' as the very first lines of your application entry point (e.g., wsgi.py, manage.py).
gotcha When using psycopg3 (psycopg package), ensure you set 'ENGINE': 'django_db_geventpool.backends.postgresql_psycopg2' even if using psycopg3. The pool backend is the same; psycopg3 support is enabled via the driver setting. ↓
fix Use ENGINE as shown in the docs and set 'OPTIONS': {'psycopg3': True} in your DATABASES config.
deprecated Direct import of backends from django_db_geventpool is deprecated. Use Django's default engine paths with custom OPTIONS instead. ↓
fix Configure DATABASES as documented, e.g. 'ENGINE': 'django_db_geventpool.backends.postgresql_psycopg2'.
Imports
- DatabaseWrapper wrong
from django_db_geventpool.backends import postgresql_psycopg2correctfrom django.db.backends.postgresql import base as pg_base; then use pg_base.DatabaseWrapper - GEVENT_POOL
from django_db_geventpool.utils import GEVENT_POOL
Quickstart
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
import django
django.setup()
from django.db import connection
cursor = connection.cursor()
cursor.execute("SELECT 1")
print(cursor.fetchone())
# Ensure gevent is patched early; use gevent.monkey.patch_all() before importing django