Skip to main content

Use Database URLs in your Django Application.

Project description

https://secure.travis-ci.org/kennethreitz/dj-database-url.png?branch=master

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), 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.

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

dj-database-url-0.4.2.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

dj_database_url-0.4.2-py2.py3-none-any.whl (5.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file dj-database-url-0.4.2.tar.gz.

File metadata

File hashes

Hashes for dj-database-url-0.4.2.tar.gz
Algorithm Hash digest
SHA256 a6832d8445ee9d788c5baa48aef8130bf61fdc442f7d9a548424d25cd85c9f08
MD5 4395ec2bd618407ba38b2645f2786c1f
BLAKE2b-256 c84bb23dbcf4c5711f26e2222bb2e300915c9c8d35e643b0af00c2d8f36c9490

See more details on using hashes here.

File details

Details for the file dj_database_url-0.4.2-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for dj_database_url-0.4.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e16d94c382ea0564c48038fa7fe8d9c890ef1ab1a8ec4cb48e732c124b9482fd
MD5 b2f129375959cf8cc8ca8b094fda21e3
BLAKE2b-256 918450cbfabb91593cff18a37046986f7c2eb69224a694a52ae614711dfa11c6

See more details on using hashes here.

Supported by

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