dj-database-url-0.5.0/0000755000076500001200000000000013246044351016274 5ustar kennethreitzadmin00000000000000dj-database-url-0.5.0/PKG-INFO0000644000076500001200000000605613246044351017400 0ustar kennethreitzadmin00000000000000Metadata-Version: 1.1 Name: dj-database-url Version: 0.5.0 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-Content-Type: UNKNOWN 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, ssl_require=True) 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.5.0/LICENSE0000644000076500001200000000240413246043450017300 0ustar kennethreitzadmin00000000000000Copyright (c) 2014, Kenneth Reitz All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. dj-database-url-0.5.0/MANIFEST.in0000644000076500001200000000002013246043450020021 0ustar kennethreitzadmin00000000000000include LICENSE dj-database-url-0.5.0/dj_database_url.egg-info/0000755000076500001200000000000013246044351023071 5ustar kennethreitzadmin00000000000000dj-database-url-0.5.0/dj_database_url.egg-info/PKG-INFO0000644000076500001200000000605613246044351024175 0ustar kennethreitzadmin00000000000000Metadata-Version: 1.1 Name: dj-database-url Version: 0.5.0 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-Content-Type: UNKNOWN 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, ssl_require=True) 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.5.0/dj_database_url.egg-info/not-zip-safe0000644000076500001200000000000113246044330025314 0ustar kennethreitzadmin00000000000000 dj-database-url-0.5.0/dj_database_url.egg-info/SOURCES.txt0000644000076500001200000000037413246044351024761 0ustar kennethreitzadmin00000000000000LICENSE MANIFEST.in README.rst dj_database_url.py 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/top_level.txtdj-database-url-0.5.0/dj_database_url.egg-info/top_level.txt0000644000076500001200000000002013246044351025613 0ustar kennethreitzadmin00000000000000dj_database_url dj-database-url-0.5.0/dj_database_url.egg-info/dependency_links.txt0000644000076500001200000000000113246044351027137 0ustar kennethreitzadmin00000000000000 dj-database-url-0.5.0/setup.py0000644000076500001200000000765713246044322020023 0ustar kennethreitzadmin00000000000000# -*- 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, ssl_require=True) 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 os import sys from shutil import rmtree from setuptools import find_packages, setup, Command VERSION = '0.5.0' here = os.path.abspath(os.path.dirname(__file__)) class UploadCommand(Command): """Support setup.py upload.""" description = 'Build and publish the package.' user_options = [] @staticmethod def status(s): """Prints things in bold.""" print('\033[1m{0}\033[0m'.format(s)) def initialize_options(self): pass def finalize_options(self): pass def run(self): try: self.status('Removing previous builds…') rmtree(os.path.join(here, 'dist')) except OSError: pass self.status('Building Source and Wheel (universal) distribution…') os.system('{0} setup.py sdist bdist_wheel --universal'.format(sys.executable)) self.status('Uploading the package to PyPi via Twine…') os.system('twine upload dist/*') self.status('Pushing git tags…') os.system('git tag v{0}'.format(VERSION)) os.system('git push --tags') sys.exit() setup( name='dj-database-url', version=VERSION, 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', ], cmdclass={ 'upload': UploadCommand, }, ) dj-database-url-0.5.0/setup.cfg0000644000076500001200000000004613246044351020115 0ustar kennethreitzadmin00000000000000[egg_info] tag_build = tag_date = 0 dj-database-url-0.5.0/README.rst0000644000076500001200000001211113246043450017756 0ustar kennethreitzadmin00000000000000DJ-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`` | +-------------+-----------------------------------------------+--------------------------------------------------+ | 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`` [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.5.0/dj_database_url.py0000644000076500001200000001053613246043707021762 0ustar kennethreitzadmin00000000000000# -*- 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('mssql') 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', 'mssql': 'sql_server.pyodbc', '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, ssl_require=False): """Returns configured DATABASE dictionary from DATABASE_URL.""" config = {} s = os.environ.get(env, default) if s: config = parse(s, engine, conn_max_age, ssl_require) return config def parse(url, engine=None, conn_max_age=0, ssl_require=False): """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. hostname = url.hostname or '' if '%2f' in hostname.lower(): # Switch to url.netloc to avoid lower cased paths hostname = url.netloc if "@" in hostname: hostname = hostname.rsplit("@", 1)[1] if ":" in hostname: hostname = hostname.split(":", 1)[0] hostname = hostname.replace('%2f', '/').replace('%2F', '/') # Lookup specified engine. engine = SCHEMES[url.scheme] if engine is None else engine port = (str(url.port) if url.port and engine == SCHEMES['oracle'] else url.port) # 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': port or '', 'CONN_MAX_AGE': conn_max_age, }) # 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] if ssl_require: options['sslmode'] = 'require' # 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