skillfed

dj-database-url

Use Database URLs in your Django Application.

dj-database-url v3.1.2 8.5M downloads/30d#1,617 on PyPI1,572
Permissive license BSD-3-Clause Active released

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-url

uv

uv add dj-database-url

poetry

poetry add dj-database-url

Installing 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

Environment :: Web EnvironmentFramework :: DjangoFramework :: Django :: 4.2Framework :: Django :: 5.2Framework :: Django :: 6Intended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Internet :: WWW/HTTP :: Dynamic ContentTopic :: Software Development :: Libraries :: Python Modules

Tags

django database url environment variable12factor database configurationdjango database connection poolingparse database url djangodjango settings from urldatabase backend url parserdjango conn_max_age configuration
django-integrationenvironment-config12factor

More Python Modules packages