Package: django-connection-url
This is a fork of Kenneth Reitz’sDJ-Database-URLextended to support cache URLs as well.There are some significant changes to the original, most notably,.parse()has been dropped. You can pass URLs and environment variables to.config().
The passed value will be first checked if it is an environment variable, and if
not found it will be parsed as a URL..config()will not useDATABASE_URLas default and therefore cannot be called without parameters.Theconnection_url.configmethod returns a Django database/cache connection
dictionary, populated with all the data specified in your URL. Multiple
dictionary objects can be passed to.config()to set default values for
settings and options. Keyword arguments passed will override any default or
parsed values.This simple Django utility allows you to utilize the12factorinspiredDATABASE_URLenvironment variable to configure your Django application.Supported DatabasesSupport currently exists for PostgreSQL, PostGIS, MySQL, MySQL (GIS),
Oracle, Oracle (GIS), and SQLite.Supported CachesSupport currently exists for Redis, Memcached and local memory cache.InstallationInstallation is simple:$ pip install django-connection-urlUsageConfigure your database insettings.pyfromDATABASE_URL:import connection_url

DATABASES['default'] = connection_url.config('DATABASE_URL')Provide an arbitrary Database URL:DATABASES['default'] = connection_url.config('postgres://...')Set default values and override with keyword arguments:connection_url.config('mysql://username:password@hostname:5432/database?TIMEOUT=100', {
                      'ENGINE': 'django.contrib.gis.db.backends.postgis',
                      'CONN_MAX_AGE': 1000,
                      'OPTIONS': {'MAX_CONNECTIONS': 120},
                      }, ENGINE='django.db.backends.postgresql_psycopg2')
#produces the following result
{
    'ENGINE': 'django.db.backends.postgresql_psycopg2',
    'NAME': 'database',
    'HOST': 'hostname',
    'PORT': 5432,
    'USER': 'username',
    'PASSWORD': 'password',
    'CONN_MAX_AGE': 1000,
    'OPTIONS': {'TIMEOUT': '100','MAX_CONNECTIONS': 120},
}The order of precedence for dict arguments, parsed values and keyword arg overrides is:Keyword arguments > Parsed values from connection URL > Defaults from passed dict objects.URL schemaEngineDjango BackendURLPostgreSQLdjango.db.backends.postgresql_psycopg2postgres://USER:PASSWORD@HOST:PORT/NAME[1]PostGISdjango.contrib.gis.db.backends.postgispostgis://USER:PASSWORD@HOST:PORT/NAMEMySQLdjango.db.backends.mysqlmysql://USER:PASSWORD@HOST:PORT/NAMEMySQL (GIS)django.contrib.gis.db.backends.mysqlmysqlgis://USER:PASSWORD@HOST:PORT/NAMESQLitedjango.db.backends.sqlite3sqlite:///PATH[2]Oracledjango.db.backends.oracleoracle://USER:PASSWORD@HOST:PORT/NAME[3]Oracle (GIS)django.contrib.gis.db.backends.oracleoraclegis://USER:PASSWORD@HOST:PORT/NAMERedisredis_cache.RedisCacheredis://USER:PASSWORD@HOST:PORT[4]Memcacheddjango.core.cache.backends.memcached.MemcachedCachememcached://USER:PASSWORD@HOST:PORTLocal memorydjango.core.cache.backends.locmem.LocMemCachelocmem://HOST:PORT/PATH[5][1]With PostgreSQL, you can also use unix domain socket paths withpercent encoding:postgres://%2Fvar%2Flib%2Fpostgresql/dbname.[2]SQLite connects to file based databases. The same URL format is used, omitting
the hostname, and using the “file” portion as the filename of the database.
This has the effect of four slashes being present for an absolute file path:sqlite:////full/path/to/your/database/file.sqlite.[3]Note that when connecting to Oracle the URL isn’t in the form you may know
from using other Oracle tools (like SQLPlus) i.e. user and password are separated
by:not by/. Also you can omitHOSTandPORTand provide a full DSN string or TNS name inNAMEpart.[4]Requiresdjango-redis-cacheto be installed.[5]For local memory cache, HOST:PORT/PATH is used as unique identifier for the cache.
If none is given, a random UUID is used as identifier.