django-envconfig


Namedjango-envconfig JSON
Version 0.4.0 PyPI version JSON
download
home_pageNone
SummaryConfigure Django using environment variables.
upload_time2024-12-20 01:22:50
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseMIT
keywords django
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # django-envconfig

[![Test](https://github.com/ely-as/django-envconfig/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/ely-as/django-envconfig/actions/workflows/test.yml)
[![Coverage](https://cov.ely.as/github/ely-as/django-envconfig/main/badge.svg)](https://cov.ely.as/github/ely-as/django-envconfig/main/latest/)
[![Version](https://img.shields.io/pypi/v/django-envconfig)](https://pypi.org/project/django-envconfig/)

![Django](https://img.shields.io/pypi/djversions/django-envconfig)
![Python](https://img.shields.io/pypi/pyversions/django-envconfig)

Configure Django using environment variables (envvars). `settings.py` optional.

## Getting started

### Installation
```sh
python -m pip install django-envconfig
```

### Usage
Edit the `manage.py`, `asgi.py` and `wsgi.py` files generated by Django's
`startproject` command and modify the following line:
```py
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'envconfig.settings')
```

### Minimum configuration
The following envvars are required (if `settings.py` is removed):
- `ALLOWED_HOSTS` (unless you set `DEBUG=on`)

Environments may be stored in an `.env` file. This file can be stored in your
root directory (next to `manage.py`) or anywhere on the path (e.g. virtualenv
directory).

## How it works

Any [Django setting](https://docs.djangoproject.com/en/3.2/ref/settings/) can
be configured as an environment variable.
- To set booleans: `true|yes|on|1` and `false|no|off|0` (case-insensitive)
- To set `None`: `none|null` (case-insensitive)
- Simple lists of strings can be stored comma-separated e.g. `export ALLOWED_HOSTS=127.0.0.1,localhost`
- Dicts and complex lists should be stored as JSON

Settings are loaded with the following priority (highest first):
1. Environment variables.
2. Settings defined in your projects `settings.py`, if it exists. Note: any
   custom settings should be defined here with their default value.
3. Settings that *would* be defined by a `settings.py` file generated by
   `startproject`. This should eliminate the need for the file in (2) for most
   projects. Caveats:
   - The default value for `DEBUG` has been changed to `False`.
   - A `SECRET_KEY` is generated but will not persist between sessions (e.g.
     if you restart your server/process manager). Check the
     [Django documentation](https://docs.djangoproject.com/en/dev/ref/settings/#secret-key)
     to see whether you need to set a persistent `SECRET_KEY` as an
     environment variable.

## django-envconfig environment variables

Helper environment variables to use with django-envconfig:

| Environment variable | Description |
| --- | --- |
| `DJANGO_PROJECT` | May be required if django-envconfig cannot find your project. Set to the name of the module originally generated by `startproject` |
| `ADD_INSTALLED_APPS` | Add to [`INSTALLED_APPS`](https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps) |
| `REMOVE_INSTALLED_APPS` | Remove from [`INSTALLED_APPS`](https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps) |
| `ADD_MIDDLEWARE` | Add to [`MIDDLEWARE`](https://docs.djangoproject.com/en/dev/topics/http/middleware/#activating-middleware) |
| `REMOVE_MIDDLEWARE` | Remove from [`MIDDLEWARE`](https://docs.djangoproject.com/en/dev/topics/http/middleware/#activating-middleware) |

### PostgreSQL environment variables

If you are using a PostgreSQL backend you do not need to set `DATABASES`. You
can simply set PostgreSQL environment variables - the minimum is `PGDATABASE`.
See the
[PostgreSQL docs](https://www.postgresql.org/docs/current/libpq-envars.html)
for the full list of envvars. This way the same environment can be used when
calling
[PostgreSQL command line utilities](https://www.postgresql.org/docs/current/reference-client.html)
such as `psql` or `pg_dump`.

## Why

- To separate configuration from code. See
  [The Twelve Factor App](https://12factor.net/).
- Use serverless services such as AWS Lambda and Heroku.
- Avoid having to template settings files and keep the auto-generated
  `settings.py` up to date between Django versions.
- Use .env files for easy switching between environments/deployments
  (e.g. dev, test and prod).

## Dependencies

- [python-dotenv](https://github.com/theskumar/python-dotenv) (BSD 3-clause license)

## License

[MIT](https://github.com/ely-as/django-envconfig/blob/main/LICENSE).

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "django-envconfig",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "django",
    "author": null,
    "author_email": "elyas <elyas@ely.as>",
    "download_url": "https://files.pythonhosted.org/packages/05/fb/b2add9ed34993ca901a6609cebad693e35dfb3d190201082cf2343587f4f/django_envconfig-0.4.0.tar.gz",
    "platform": null,
    "description": "# django-envconfig\n\n[![Test](https://github.com/ely-as/django-envconfig/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/ely-as/django-envconfig/actions/workflows/test.yml)\n[![Coverage](https://cov.ely.as/github/ely-as/django-envconfig/main/badge.svg)](https://cov.ely.as/github/ely-as/django-envconfig/main/latest/)\n[![Version](https://img.shields.io/pypi/v/django-envconfig)](https://pypi.org/project/django-envconfig/)\n\n![Django](https://img.shields.io/pypi/djversions/django-envconfig)\n![Python](https://img.shields.io/pypi/pyversions/django-envconfig)\n\nConfigure Django using environment variables (envvars). `settings.py` optional.\n\n## Getting started\n\n### Installation\n```sh\npython -m pip install django-envconfig\n```\n\n### Usage\nEdit the `manage.py`, `asgi.py` and `wsgi.py` files generated by Django's\n`startproject` command and modify the following line:\n```py\nos.environ.setdefault('DJANGO_SETTINGS_MODULE', 'envconfig.settings')\n```\n\n### Minimum configuration\nThe following envvars are required (if `settings.py` is removed):\n- `ALLOWED_HOSTS` (unless you set `DEBUG=on`)\n\nEnvironments may be stored in an `.env` file. This file can be stored in your\nroot directory (next to `manage.py`) or anywhere on the path (e.g. virtualenv\ndirectory).\n\n## How it works\n\nAny [Django setting](https://docs.djangoproject.com/en/3.2/ref/settings/) can\nbe configured as an environment variable.\n- To set booleans: `true|yes|on|1` and `false|no|off|0` (case-insensitive)\n- To set `None`: `none|null` (case-insensitive)\n- Simple lists of strings can be stored comma-separated e.g. `export ALLOWED_HOSTS=127.0.0.1,localhost`\n- Dicts and complex lists should be stored as JSON\n\nSettings are loaded with the following priority (highest first):\n1. Environment variables.\n2. Settings defined in your projects `settings.py`, if it exists. Note: any\n   custom settings should be defined here with their default value.\n3. Settings that *would* be defined by a `settings.py` file generated by\n   `startproject`. This should eliminate the need for the file in (2) for most\n   projects. Caveats:\n   - The default value for `DEBUG` has been changed to `False`.\n   - A `SECRET_KEY` is generated but will not persist between sessions (e.g.\n     if you restart your server/process manager). Check the\n     [Django documentation](https://docs.djangoproject.com/en/dev/ref/settings/#secret-key)\n     to see whether you need to set a persistent `SECRET_KEY` as an\n     environment variable.\n\n## django-envconfig environment variables\n\nHelper environment variables to use with django-envconfig:\n\n| Environment variable | Description |\n| --- | --- |\n| `DJANGO_PROJECT` | May be required if django-envconfig cannot find your project. Set to the name of the module originally generated by `startproject` |\n| `ADD_INSTALLED_APPS` | Add to [`INSTALLED_APPS`](https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps) |\n| `REMOVE_INSTALLED_APPS` | Remove from [`INSTALLED_APPS`](https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps) |\n| `ADD_MIDDLEWARE` | Add to [`MIDDLEWARE`](https://docs.djangoproject.com/en/dev/topics/http/middleware/#activating-middleware) |\n| `REMOVE_MIDDLEWARE` | Remove from [`MIDDLEWARE`](https://docs.djangoproject.com/en/dev/topics/http/middleware/#activating-middleware) |\n\n### PostgreSQL environment variables\n\nIf you are using a PostgreSQL backend you do not need to set `DATABASES`. You\ncan simply set PostgreSQL environment variables - the minimum is `PGDATABASE`.\nSee the\n[PostgreSQL docs](https://www.postgresql.org/docs/current/libpq-envars.html)\nfor the full list of envvars. This way the same environment can be used when\ncalling\n[PostgreSQL command line utilities](https://www.postgresql.org/docs/current/reference-client.html)\nsuch as `psql` or `pg_dump`.\n\n## Why\n\n- To separate configuration from code. See\n  [The Twelve Factor App](https://12factor.net/).\n- Use serverless services such as AWS Lambda and Heroku.\n- Avoid having to template settings files and keep the auto-generated\n  `settings.py` up to date between Django versions.\n- Use .env files for easy switching between environments/deployments\n  (e.g. dev, test and prod).\n\n## Dependencies\n\n- [python-dotenv](https://github.com/theskumar/python-dotenv) (BSD 3-clause license)\n\n## License\n\n[MIT](https://github.com/ely-as/django-envconfig/blob/main/LICENSE).\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Configure Django using environment variables.",
    "version": "0.4.0",
    "project_urls": {
        "Issue Tracker": "https://github.com/ely-as/django-envconfig/issues",
        "Source": "https://github.com/ely-as/django-envconfig"
    },
    "split_keywords": [
        "django"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a8d7724d45d17e70c03a0ef4a0d71b7b18204d3ea6e2cdfa246d432095863095",
                "md5": "02ae289205895b7f699bd1ec1aca70c7",
                "sha256": "38e07ab8beda22e5548ec3c33f2f0109f482af9afed84f11d42b75bb58f4edd7"
            },
            "downloads": -1,
            "filename": "django_envconfig-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "02ae289205895b7f699bd1ec1aca70c7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 11130,
            "upload_time": "2024-12-20T01:22:49",
            "upload_time_iso_8601": "2024-12-20T01:22:49.835377Z",
            "url": "https://files.pythonhosted.org/packages/a8/d7/724d45d17e70c03a0ef4a0d71b7b18204d3ea6e2cdfa246d432095863095/django_envconfig-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "05fbb2add9ed34993ca901a6609cebad693e35dfb3d190201082cf2343587f4f",
                "md5": "777bb8b5011b43c7d25428a21371349d",
                "sha256": "6fba8d758a078c5022963986ff0bd34bbdb10a9f1b291f680d517579445ef2cb"
            },
            "downloads": -1,
            "filename": "django_envconfig-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "777bb8b5011b43c7d25428a21371349d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 10907,
            "upload_time": "2024-12-20T01:22:50",
            "upload_time_iso_8601": "2024-12-20T01:22:50.930608Z",
            "url": "https://files.pythonhosted.org/packages/05/fb/b2add9ed34993ca901a6609cebad693e35dfb3d190201082cf2343587f4f/django_envconfig-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-20 01:22:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ely-as",
    "github_project": "django-envconfig",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "django-envconfig"
}
        
Elapsed time: 0.83447s