dj-database-url
Use Database URLs in your Django Application.
What it is and what it does
dj-database-url is a lightweight utility that converts DATABASE_URL environment variables into Django database configuration dictionaries. It implements the 12factor pattern for backing services, allowing you to externalize database connection details into environment variables rather than hardcoding them in settings.py. The package handles URL parsing for multiple database engines—PostgreSQL, MySQL, Oracle, SQLite, PostGIS, Redshift, CockroachDB, Timescale, and others—and automatically maps them to the correct Django backend.
The main entry points are config() (reads from DATABASE_URL environment variable with optional fallback) and parse() (accepts a URL string directly). Both return a Django DATABASES dictionary entry. The package also supports Django's connection pooling via conn_max_age and health checks via conn_health_checks, and allows registration of custom database backends with optional post-processing functions for non-standard configuration needs.
Use it for:
- Containerized deployments where database credentials are injected via environment variables at runtime.
- Multi-environment setups (dev, staging, production) using the same code with different DATABASE_URL values.
- Enabling connection pooling and health checks in Django without manual DATABASES dictionary construction.
- Supporting non-standard or custom database backends by registering them with dj_database_url.register().
- Migrating from hardcoded database settings to environment-driven configuration in existing Django projects.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Parses DATABASE_URL environment variables into Django database configuration dictionaries, supporting PostgreSQL, MySQL, Oracle, SQLite, and other backends with optional connection pooling.
Yes. This is a stable, actively maintained utility with zero known vulnerabilities, low install friction, and broad database backend support. It directly solves the common problem of externalizing database configuration in Django applications and is widely used in containerized and cloud-deployed environments. Install it if you use Django and want to follow 12factor principles for database configuration.
Install
dj-database-url on PyPI
pip
pip install dj-database-urluv
uv add dj-database-urlpoetry
poetry add dj-database-urlInstalling dj-database-url
Before you install
Low friction: single dependency on django, wheel-only distribution, actively maintained with recent commits. Supports current Python versions (3.10–3.14) and Django 4.2 through 6.
License in practice
BSD-3-Clause (permissive): you may use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
Quickstart
import dj_database_url
DATABASES = {
'default': dj_database_url.config(
conn_max_age=600,
conn_health_checks=True,
)
}
Requires DATABASE_URL environment variable to be set, or a default URL passed to config(); special characters in URLs must be percent-encoded.
Verify before relying
- Whether custom backend registration persists across application reloads or requires per-request setup.
- Performance impact of connection health checks on request latency in high-throughput scenarios.
Package facts
| License | BSD-3-Clause (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — django |
| Maintenance | actively maintained — 176 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 8,506,063/month — #1,617 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: dj_database_url-3.1.2-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
django-db-connection-poolProvides connection pooling for Django database…
permissive · top 15,000 on PyPI
dsnparseParses DSN (Data Source Name) connection URL…
permissive · top 15,000 on PyPI
django-db-geventpoolProvides a gevent-based connection pool for…
permissive · top 15,000 on PyPI
dbt-copilot-pythonProvides utility functions for running Django…
unclear · top 15,000 on PyPI
django-herokuConfigures Django applications for Heroku…
permissive · top 15,000 on PyPI
django-snowflakeProvides a Django database backend that…
permissive · top 15,000 on PyPI
mssql-djangoDjango database backend that connects Django…
permissive · top 15,000 on PyPI
sqlalchemy-jdbcapiSQLAlchemy dialect for JDBC and ODBC database…
permissive · top 15,000 on PyPI
databasesProvides async database access for PostgreSQL,…
permissive · top 5,000 on PyPI
django-pg-returningExtends Django's ORM to capture and return rows…
permissive · top 15,000 on PyPI