dj-database-url-0.4.2/0000755000076500000240000000000013033503275016312 5ustar kennethreitzstaff00000000000000dj-database-url-0.4.2/dj_database_url.egg-info/0000755000076500000240000000000013033503275023107 5ustar kennethreitzstaff00000000000000dj-database-url-0.4.2/dj_database_url.egg-info/dependency_links.txt0000644000076500000240000000000113033503274027154 0ustar kennethreitzstaff00000000000000 dj-database-url-0.4.2/dj_database_url.egg-info/not-zip-safe0000644000076500000240000000000112654507035025343 0ustar kennethreitzstaff00000000000000 dj-database-url-0.4.2/dj_database_url.egg-info/pbr.json0000644000076500000240000000005712654507261024576 0ustar kennethreitzstaff00000000000000{"is_release": false, "git_version": "24c9152"}dj-database-url-0.4.2/dj_database_url.egg-info/PKG-INFO0000644000076500000240000000577213033503274024216 0ustar kennethreitzstaff00000000000000Metadata-Version: 1.1 Name: dj-database-url Version: 0.4.2 Summary: Use Database URLs in your Django Application. Home-page: https://github.com/kennethreitz/dj-database-url Author: Kenneth Reitz Author-email: me@kennethreitz.com License: BSD Description: dj-database-url ~~~~~~~~~~~~~~~ .. image:: https://secure.travis-ci.org/kennethreitz/dj-database-url.png?branch=master :target: http://travis-ci.org/kennethreitz/dj-database-url 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. Platform: any Classifier: Environment :: Web Environment Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content Classifier: Topic :: Software Development :: Libraries :: Python Modules Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 dj-database-url-0.4.2/dj_database_url.egg-info/SOURCES.txt0000644000076500000240000000042413033503274024772 0ustar kennethreitzstaff00000000000000README.rst dj_database_url.py setup.cfg setup.py dj_database_url.egg-info/PKG-INFO dj_database_url.egg-info/SOURCES.txt dj_database_url.egg-info/dependency_links.txt dj_database_url.egg-info/not-zip-safe dj_database_url.egg-info/pbr.json dj_database_url.egg-info/top_level.txtdj-database-url-0.4.2/dj_database_url.egg-info/top_level.txt0000644000076500000240000000002013033503274025630 0ustar kennethreitzstaff00000000000000dj_database_url dj-database-url-0.4.2/dj_database_url.py0000644000076500000240000000775013033503146021775 0ustar kennethreitzstaff00000000000000# -*- coding: utf-8 -*- import os try: import urlparse except ImportError: import urllib.parse as urlparse # Register database schemes in URLs. urlparse.uses_netloc.append('postgres') urlparse.uses_netloc.append('postgresql') urlparse.uses_netloc.append('pgsql') urlparse.uses_netloc.append('postgis') urlparse.uses_netloc.append('mysql') urlparse.uses_netloc.append('mysql2') urlparse.uses_netloc.append('mysqlgis') urlparse.uses_netloc.append('mysql-connector') urlparse.uses_netloc.append('spatialite') urlparse.uses_netloc.append('sqlite') urlparse.uses_netloc.append('oracle') urlparse.uses_netloc.append('oraclegis') urlparse.uses_netloc.append('redshift') DEFAULT_ENV = 'DATABASE_URL' SCHEMES = { 'postgres': 'django.db.backends.postgresql_psycopg2', 'postgresql': 'django.db.backends.postgresql_psycopg2', 'pgsql': 'django.db.backends.postgresql_psycopg2', 'postgis': 'django.contrib.gis.db.backends.postgis', 'mysql': 'django.db.backends.mysql', 'mysql2': 'django.db.backends.mysql', 'mysqlgis': 'django.contrib.gis.db.backends.mysql', 'mysql-connector': 'mysql.connector.django', 'spatialite': 'django.contrib.gis.db.backends.spatialite', 'sqlite': 'django.db.backends.sqlite3', 'oracle': 'django.db.backends.oracle', 'oraclegis': 'django.contrib.gis.db.backends.oracle', 'redshift': 'django_redshift_backend', } def config(env=DEFAULT_ENV, default=None, engine=None, conn_max_age=0): """Returns configured DATABASE dictionary from DATABASE_URL.""" config = {} s = os.environ.get(env, default) if s: config = parse(s, engine, conn_max_age) return config def parse(url, engine=None, conn_max_age=0): """Parses a database URL.""" if url == 'sqlite://:memory:': # this is a special case, because if we pass this URL into # urlparse, urlparse will choke trying to interpret "memory" # as a port number return { 'ENGINE': SCHEMES['sqlite'], 'NAME': ':memory:' } # note: no other settings are required for sqlite # otherwise parse the url as normal config = {} url = urlparse.urlparse(url) # Split query strings from path. path = url.path[1:] if '?' in path and not url.query: path, query = path.split('?', 2) else: path, query = path, url.query query = urlparse.parse_qs(query) # If we are using sqlite and we have no path, then assume we # want an in-memory database (this is the behaviour of sqlalchemy) if url.scheme == 'sqlite' and path == '': path = ':memory:' # Handle postgres percent-encoded paths. netloc = url.netloc if "@" in netloc: netloc = netloc.rsplit("@", 1)[1] if ":" in netloc: netloc = netloc.split(":", 1)[0] hostname = netloc or '' if '%2f' in hostname.lower(): hostname = hostname.replace('%2f', '/').replace('%2F', '/') # Update with environment configuration. config.update({ 'NAME': urlparse.unquote(path or ''), 'USER': urlparse.unquote(url.username or ''), 'PASSWORD': urlparse.unquote(url.password or ''), 'HOST': hostname, 'PORT': url.port or '', 'CONN_MAX_AGE': conn_max_age, }) # Lookup specified engine. engine = SCHEMES[url.scheme] if engine is None else engine # Pass the query string into OPTIONS. options = {} for key, values in query.items(): if url.scheme == 'mysql' and key == 'ssl-ca': options['ssl'] = {'ca': values[-1]} continue options[key] = values[-1] # Support for Postgres Schema URLs if 'currentSchema' in options and engine in ( 'django.contrib.gis.db.backends.postgis', 'django.db.backends.postgresql_psycopg2', 'django_redshift_backend', ): options['options'] = '-c search_path={0}'.format(options.pop('currentSchema')) if options: config['OPTIONS'] = options if engine: config['ENGINE'] = engine return config dj-database-url-0.4.2/PKG-INFO0000644000076500000240000000577213033503275017422 0ustar kennethreitzstaff00000000000000Metadata-Version: 1.1 Name: dj-database-url Version: 0.4.2 Summary: Use Database URLs in your Django Application. Home-page: https://github.com/kennethreitz/dj-database-url Author: Kenneth Reitz Author-email: me@kennethreitz.com License: BSD Description: dj-database-url ~~~~~~~~~~~~~~~ .. image:: https://secure.travis-ci.org/kennethreitz/dj-database-url.png?branch=master :target: http://travis-ci.org/kennethreitz/dj-database-url 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. Platform: any Classifier: Environment :: Web Environment Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content Classifier: Topic :: Software Development :: Libraries :: Python Modules Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.2 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 dj-database-url-0.4.2/README.rst0000644000076500000240000001154313033503146020002 0ustar kennethreitzstaff00000000000000DJ-Database-URL ~~~~~~~~~~~~~~~ .. image:: https://secure.travis-ci.org/kennethreitz/dj-database-url.svg?branch=master :target: http://travis-ci.org/kennethreitz/dj-database-url 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_psycopg2`` | ``postgres://USER:PASSWORD@HOST:PORT/NAME`` [1]_ | +-------------+-----------------------------------------------+--------------------------------------------------+ | PostGIS | ``django.contrib.gis.db.backends.postgis`` | ``postgis://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`` [2]_ | +-------------+-----------------------------------------------+--------------------------------------------------+ | SpatiaLite | ``django.contrib.gis.db.backends.spatialite`` | ``spatialite:///PATH`` [2]_ | +-------------+-----------------------------------------------+--------------------------------------------------+ | Oracle | ``django.db.backends.oracle`` | ``oracle://USER:PASSWORD@HOST:PORT/NAME`` [3]_ | +-------------+-----------------------------------------------+--------------------------------------------------+ | Oracle (GIS)| ``django.contrib.gis.db.backends.oracle`` | ``oraclegis://USER:PASSWORD@HOST:PORT/NAME`` | +-------------+-----------------------------------------------+--------------------------------------------------+ | Redshift | ``django_redshift_backend`` | ``redshift://USER:PASSWORD@HOST:PORT/NAME`` | +-------------+-----------------------------------------------+--------------------------------------------------+ .. [1] With PostgreSQL, you can also use unix domain socket paths with `percent 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 omit ``HOST`` and ``PORT`` and provide a full DSN string or TNS name in ``NAME`` part. dj-database-url-0.4.2/setup.cfg0000644000076500000240000000012213033503275020126 0ustar kennethreitzstaff00000000000000[wheel] universal = 1 [egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 dj-database-url-0.4.2/setup.py0000644000076500000240000000563013033503271020024 0ustar kennethreitzstaff00000000000000# -*- coding: utf-8 -*- """ dj-database-url ~~~~~~~~~~~~~~~ .. image:: https://secure.travis-ci.org/kennethreitz/dj-database-url.png?branch=master :target: http://travis-ci.org/kennethreitz/dj-database-url 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. """ import sys import os from setuptools import setup if sys.argv[-1] == "publish": os.system("python setup.py sdist bdist_wheel upload") sys.exit() setup( name='dj-database-url', version='0.4.2', url='https://github.com/kennethreitz/dj-database-url', license='BSD', author='Kenneth Reitz', author_email='me@kennethreitz.com', description='Use Database URLs in your Django Application.', long_description=__doc__, py_modules=['dj_database_url'], zip_safe=False, include_package_data=True, platforms='any', classifiers=[ 'Environment :: Web Environment', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', 'Topic :: Software Development :: Libraries :: Python Modules', 'Programming Language :: Python', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.2', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', ] )