{"id":13419455,"url":"https://github.com/jazzband/dj-database-url","last_synced_at":"2026-01-04T11:09:09.690Z","repository":{"id":3154857,"uuid":"4185033","full_name":"jazzband/dj-database-url","owner":"jazzband","description":"Use Database URLs in your Django Application.","archived":false,"fork":false,"pushed_at":"2025-12-19T13:17:28.000Z","size":296,"stargazers_count":1548,"open_issues_count":8,"forks_count":213,"subscribers_count":30,"default_branch":"master","last_synced_at":"2025-12-22T03:07:36.731Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pypi.org/project/dj-database-url/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jazzband.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"custom":["https://jazzband.co/donate"]}},"created_at":"2012-04-30T17:20:23.000Z","updated_at":"2025-12-19T13:14:19.000Z","dependencies_parsed_at":"2024-01-11T19:17:19.364Z","dependency_job_id":"9a094d6d-44cd-443f-9340-ae7e6a013f52","html_url":"https://github.com/jazzband/dj-database-url","commit_stats":{"total_commits":241,"total_committers":71,"mean_commits":"3.3943661971830985","dds":0.8630705394190872,"last_synced_commit":"08d9cf0978f6c911417f13f441773ac569905a63"},"previous_names":["jacobian/dj-database-url"],"tags_count":25,"template":false,"template_full_name":null,"purl":"pkg:github/jazzband/dj-database-url","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jazzband%2Fdj-database-url","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jazzband%2Fdj-database-url/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jazzband%2Fdj-database-url/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jazzband%2Fdj-database-url/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jazzband","download_url":"https://codeload.github.com/jazzband/dj-database-url/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jazzband%2Fdj-database-url/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28201343,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2026-01-04T02:00:06.065Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T22:01:16.289Z","updated_at":"2026-01-04T11:09:09.662Z","avatar_url":"https://github.com/jazzband.png","language":"Python","funding_links":["https://jazzband.co/donate"],"categories":["Python","Third-Party Packages","Django Utilities"],"sub_categories":["URLs"],"readme":"DJ-Database-URL\n~~~~~~~~~~~~~~~\n\n.. image:: https://jazzband.co/static/img/badge.png\n   :target: https://jazzband.co/\n   :alt: Jazzband\n\n.. image:: https://github.com/jazzband/dj-database-url/actions/workflows/test.yml/badge.svg\n   :target: https://github.com/jazzband/dj-database-url/actions/workflows/test.yml\n\n.. image:: https://codecov.io/gh/jazzband/dj-database-url/branch/master/graph/badge.svg?token=7srBUpszOa\n   :target: https://codecov.io/gh/jazzband/dj-database-url\n\nThis simple Django utility allows you to utilize the\n`12factor \u003chttp://www.12factor.net/backing-services\u003e`_ inspired\n``DATABASE_URL`` environment variable to configure your Django application.\n\nThe ``dj_database_url.config`` method returns a Django database connection\ndictionary, populated with all the data specified in your URL. There is\nalso a `conn_max_age` argument to easily enable Django's connection pool.\n\nIf you'd rather not use an environment variable, you can pass a URL in directly\ninstead to ``dj_database_url.parse``.\n\nInstallation\n------------\n\nInstallation is simple:\n\n.. code-block:: console\n\n    $ pip install dj-database-url\n\nUsage\n-----\n\n1. If ``DATABASES`` is already defined:\n\n- Configure your database in ``settings.py`` from ``DATABASE_URL``:\n\n  .. code-block:: python\n\n      import dj_database_url\n\n      DATABASES['default'] = dj_database_url.config(\n          conn_max_age=600,\n          conn_health_checks=True,\n      )\n\n- Provide a default:\n\n  .. code-block:: python\n\n      DATABASES['default'] = dj_database_url.config(\n          default='postgres://...',\n          conn_max_age=600,\n          conn_health_checks=True,\n      )\n\n- Parse an arbitrary Database URL:\n\n  .. code-block:: python\n\n      DATABASES['default'] = dj_database_url.parse(\n          'postgres://...',\n          conn_max_age=600,\n          conn_health_checks=True,\n      )\n\n2. If ``DATABASES`` is not defined:\n\n- Configure your database in ``settings.py`` from ``DATABASE_URL``:\n\n  .. code-block:: python\n\n      import dj_database_url\n\n      DATABASES = {\n          'default': dj_database_url.config(\n              conn_max_age=600,\n              conn_health_checks=True,\n          ),\n      }\n\n- You can provide a default, used if the ``DATABASE_URL`` setting is not defined:\n\n  .. code-block:: python\n\n      DATABASES = {\n          'default': dj_database_url.config(\n              default='postgres://...',\n              conn_max_age=600,\n              conn_health_checks=True,\n          )\n      }\n\n- Parse an arbitrary Database URL:\n\n  .. code-block:: python\n\n      DATABASES = {\n          'default': dj_database_url.parse(\n              'postgres://...',\n              conn_max_age=600,\n              conn_health_checks=True,\n          )\n      }\n\n``conn_max_age`` sets the |CONN_MAX_AGE setting|__, which tells Django to\npersist database connections between requests, up to the given lifetime in\nseconds. If you do not provide a value, it will follow Django’s default of\n``0``. Setting it is recommended for performance.\n\n.. |CONN_MAX_AGE setting| replace:: ``CONN_MAX_AGE`` setting\n__ https://docs.djangoproject.com/en/stable/ref/settings/#conn-max-age\n\n``conn_health_checks`` sets the |CONN_HEALTH_CHECKS setting|__ (new in Django\n4.1), which tells Django to check a persisted connection still works at the\nstart of each request. If you do not provide a value, it will follow Django’s\ndefault of ``False``. Enabling it is recommended if you set a non-zero\n``conn_max_age``.\n\n.. |CONN_HEALTH_CHECKS setting| replace:: ``CONN_HEALTH_CHECKS`` setting\n__ https://docs.djangoproject.com/en/stable/ref/settings/#conn-health-checks\n\nStrings passed to `dj_database_url` must be valid URLs; in\nparticular, special characters must be url-encoded. The following url will raise\na `ValueError`:\n\n.. code-block:: plaintext\n\n    postgres://user:p#ssword!@localhost/foobar\n\nand should instead be passed as:\n\n.. code-block:: plaintext\n\n    postgres://user:p%23ssword!@localhost/foobar\n\n`TEST \u003chttps://docs.djangoproject.com/en/stable/ref/settings/#test\u003e`_ settings can be configured using the ``test_options`` attribute::\n\n    DATABASES['default'] = dj_database_url.config(default='postgres://...', test_options={'NAME': 'mytestdatabase'})\n\n\nSupported Databases\n-------------------\n\nSupport currently exists for PostgreSQL, PostGIS, MySQL, MySQL (GIS),\nOracle, Oracle (GIS), Redshift, CockroachDB, Timescale, Timescale (GIS) and SQLite.\n\nIf you want to use\nsome non-default backends, you need to register them first:\n\n.. code-block:: python\n\n    import dj_database_url\n\n    # registration should be performed only once\n    dj_database_url.register(\"mysql-connector\", \"mysql.connector.django\")\n\n    assert dj_database_url.parse(\"mysql-connector://user:password@host:port/db-name\") == {\n        \"ENGINE\": \"mysql.connector.django\",\n        # ...other connection params\n    }\n\nSome backends need further config adjustments (e.g. oracle and mssql\nexpect ``PORT`` to be a string). For such cases you can provide a\npost-processing function to ``register()`` (note that ``register()`` is\nused as a **decorator(!)** in this case):\n\n.. code-block:: python\n\n    import dj_database_url\n\n    @dj_database_url.register(\"mssql\", \"sql_server.pyodbc\")\n    def stringify_port(config):\n        config[\"PORT\"] = str(config[\"PORT\"])\n\n    @dj_database_url.register(\"redshift\", \"django_redshift_backend\")\n    def apply_current_schema(config):\n        options = config[\"OPTIONS\"]\n        schema = options.pop(\"currentSchema\", None)\n        if schema:\n            options[\"options\"] = f\"-c search_path={schema}\"\n\n    @dj_database_url.register(\"snowflake\", \"django_snowflake\")\n    def adjust_snowflake_config(config):\n        config.pop(\"PORT\", None)\n        config[\"ACCOUNT\"] = config.pop(\"HOST\")\n        name, _, schema = config[\"NAME\"].partition(\"/\")\n        if schema:\n            config[\"SCHEMA\"] = schema\n            config[\"NAME\"] = name\n        options = config.get(\"OPTIONS\", {})\n        warehouse = options.pop(\"warehouse\", None)\n        if warehouse:\n            config[\"WAREHOUSE\"] = warehouse\n        role = options.pop(\"role\", None)\n        if role:\n            config[\"ROLE\"] = role\n\nURL schema\n----------\n\n+----------------------+-----------------------------------------------+--------------------------------------------------+\n| Engine               | Django Backend                                | URL                                              |\n+======================+===============================================+==================================================+\n| PostgreSQL           | ``django.db.backends.postgresql`` [1]_        | ``postgres://USER:PASSWORD@HOST:PORT/NAME`` [2]_ |\n|                      |                                               | ``postgresql://USER:PASSWORD@HOST:PORT/NAME``    |\n+----------------------+-----------------------------------------------+--------------------------------------------------+\n| PostGIS              | ``django.contrib.gis.db.backends.postgis``    | ``postgis://USER:PASSWORD@HOST:PORT/NAME``       |\n+----------------------+-----------------------------------------------+--------------------------------------------------+\n| MSSQL                | ``sql_server.pyodbc``                         | ``mssql://USER:PASSWORD@HOST:PORT/NAME``         |\n+----------------------+-----------------------------------------------+--------------------------------------------------+\n| MSSQL [5]_           | ``mssql``                                     | ``mssqlms://USER:PASSWORD@HOST:PORT/NAME``       |\n+----------------------+-----------------------------------------------+--------------------------------------------------+\n| MySQL                | ``django.db.backends.mysql``                  | ``mysql://USER:PASSWORD@HOST:PORT/NAME`` [2]_    |\n+----------------------+-----------------------------------------------+--------------------------------------------------+\n| MySQL (GIS)          | ``django.contrib.gis.db.backends.mysql``      | ``mysqlgis://USER:PASSWORD@HOST:PORT/NAME``      |\n+----------------------+-----------------------------------------------+--------------------------------------------------+\n| SQLite               | ``django.db.backends.sqlite3``                | ``sqlite:///PATH`` [3]_                          |\n+----------------------+-----------------------------------------------+--------------------------------------------------+\n| SpatiaLite           | ``django.contrib.gis.db.backends.spatialite`` | ``spatialite:///PATH`` [3]_                      |\n+----------------------+-----------------------------------------------+--------------------------------------------------+\n| Oracle               | ``django.db.backends.oracle``                 | ``oracle://USER:PASSWORD@HOST:PORT/NAME`` [4]_   |\n+----------------------+-----------------------------------------------+--------------------------------------------------+\n| Oracle (GIS)         | ``django.contrib.gis.db.backends.oracle``     | ``oraclegis://USER:PASSWORD@HOST:PORT/NAME``     |\n+----------------------+-----------------------------------------------+--------------------------------------------------+\n| Redshift             | ``django_redshift_backend``                   | ``redshift://USER:PASSWORD@HOST:PORT/NAME``      |\n+----------------------+-----------------------------------------------+--------------------------------------------------+\n| CockroachDB          | ``django_cockroachdb``                        | ``cockroach://USER:PASSWORD@HOST:PORT/NAME``     |\n+----------------------+-----------------------------------------------+--------------------------------------------------+\n| Timescale [6]_       | ``timescale.db.backends.postgresql``          | ``timescale://USER:PASSWORD@HOST:PORT/NAME``     |\n+----------------------+-----------------------------------------------+--------------------------------------------------+\n| Timescale (GIS) [6]_ | ``timescale.db.backend.postgis``              | ``timescalegis://USER:PASSWORD@HOST:PORT/NAME``  |\n+----------------------+-----------------------------------------------+--------------------------------------------------+\n\n.. [1] The django.db.backends.postgresql backend is named django.db.backends.postgresql_psycopg2 in older releases. For\n       backwards compatibility, the old name still works in newer versions. (The new name does not work in older versions).\n.. [2] With PostgreSQL or CloudSQL, you can also use unix domain socket paths with\n       `percent encoding \u003chttp://www.postgresql.org/docs/9.2/interactive/libpq-connect.html#AEN38162\u003e`_:\n       ``postgres://%2Fvar%2Flib%2Fpostgresql/dbname``\n       ``mysql://uf07k1i6d8ia0v@%2fcloudsql%2fproject%3alocation%3ainstance/dbname``\n.. [3] SQLite connects to file based databases. The same URL format is used, omitting\n       the hostname, and using the \"file\" portion as the filename of the database.\n       This has the effect of four slashes being present for an absolute file path:\n       ``sqlite:////full/path/to/your/database/file.sqlite``.\n.. [4] Note that when connecting to Oracle the URL isn't in the form you may know\n       from using other Oracle tools (like SQLPlus) i.e. user and password are separated\n       by ``:`` not by ``/``. Also you can omit ``HOST`` and ``PORT``\n       and provide a full DSN string or TNS name in ``NAME`` part.\n.. [5] Microsoft official `mssql-django \u003chttps://github.com/microsoft/mssql-django\u003e`_ adapter.\n.. [6] Using the django-timescaledb Package which must be installed.\n\n\nContributing\n------------\n\nWe welcome contributions to this project. Projects can take two forms:\n\n1. Raising issues or helping others through the github issue tracker.\n2. Contributing code.\n\nRaising Issues or helping others:\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nWhen submitting an issue or helping other remember you are talking to humans who have feelings, jobs and lives of their\nown. Be nice, be kind, be polite. Remember english may not be someone first language, if you do not understand or\nsomething is not clear be polite and re-ask/ re-word.\n\nContributing code:\n^^^^^^^^^^^^^^^^^^\n\n* Before writing code be sure to check existing PR's and issues in the tracker.\n* Write code to the pylint spec.\n* Large or wide sweeping changes will take longer, and may face more scrutiny than smaller confined changes.\n* Code should be pass `black` and `flake8` validation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjazzband%2Fdj-database-url","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjazzband%2Fdj-database-url","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjazzband%2Fdj-database-url/lists"}