Skip to main content

Use Database URLs in your Django Application.

Project description

https://img.shields.io/endpoint.svg?url=https%3A%2F%2Factions-badge.atrox.dev%2Fjacobian%2Fdj-database-url%2Fbadge&style=for-the-badge

This simple Django utility allows you to utilize the 12factor inspired DATABASE_URL environment variable to configure your Django application.

The dj_database_url.config method returns a Django database connection dictionary, populated with all the data specified in your URL. There is also a conn_max_age argument to easily enable Django’s connection pool.

If you’d rather not use an environment variable, you can pass a URL in directly instead to dj_database_url.parse.

Supported Databases

Support currently exists for PostgreSQL, PostGIS, MySQL, MySQL (GIS), Oracle, Oracle (GIS), Redshift, and SQLite.

Installation

Installation is simple:

$ pip install dj-database-url

Usage

Configure your database in settings.py from DATABASE_URL:

import dj_database_url

DATABASES['default'] = dj_database_url.config(conn_max_age=600)

Provide a default:

DATABASES['default'] = dj_database_url.config(default='postgres://...')

Parse an arbitrary Database URL:

DATABASES['default'] = dj_database_url.parse('postgres://...', conn_max_age=600)

The conn_max_age attribute is the lifetime of a database connection in seconds and is available in Django 1.6+. If you do not set a value, it will default to 0 which is Django’s historical behavior of using a new database connection on each request. Use None for unlimited persistent connections.

URL schema

Engine

Django Backend

URL

PostgreSQL

django.db.backends.postgresql [1]

postgres://USER:PASSWORD@HOST:PORT/NAME [2]

PostGIS

django.contrib.gis.db.backends.postgis

postgis://USER:PASSWORD@HOST:PORT/NAME

MSSQL

sql_server.pyodbc

mssql://USER:PASSWORD@HOST:PORT/NAME

MySQL

django.db.backends.mysql

mysql://USER:PASSWORD@HOST:PORT/NAME

MySQL (GIS)

django.contrib.gis.db.backends.mysql

mysqlgis://USER:PASSWORD@HOST:PORT/NAME

SQLite

django.db.backends.sqlite3

sqlite:///PATH [3]

SpatiaLite

django.contrib.gis.db.backends.spatialite

spatialite:///PATH [3]

Oracle

django.db.backends.oracle

oracle://USER:PASSWORD@HOST:PORT/NAME [4]

Oracle (GIS)

django.contrib.gis.db.backends.oracle

oraclegis://USER:PASSWORD@HOST:PORT/NAME

Redshift

django_redshift_backend

redshift://USER:PASSWORD@HOST:PORT/NAME

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-database-url-1.0.3.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

django_database_url-1.0.3-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file django-database-url-1.0.3.tar.gz.

File metadata

  • Download URL: django-database-url-1.0.3.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for django-database-url-1.0.3.tar.gz
Algorithm Hash digest
SHA256 141077780995d38c4a68a0d32d5affb016f288f54ff4f6296a9f1fee9e44aae3
MD5 fdcfa91de4e40026269bf5c4f8d434c8
BLAKE2b-256 ca3aae60cee85877e634b2e48807942bdc0959fe12f26db6b3da365a3f1d2c01

See more details on using hashes here.

File details

Details for the file django_database_url-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: django_database_url-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for django_database_url-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d2e652fd9f4435b80725ad15691d7ea33ead56950614b9acc451c778f8bd2a1f
MD5 1e60e412159b9882574309046c7e7000
BLAKE2b-256 37d52ae1392790cdecaa49f330acfc39983e4a4021f2da407e634930ded9ba2a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page