django-envconfig


Namedjango-envconfig JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/ely-as/django-envconfig
SummaryConfigure Django using environment variables.
upload_time2020-11-22 04:01:24
maintainer
docs_urlNone
authorElyas Khan
requires_python
licenseMIT
keywords
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/workflows/Test/badge.svg)
![Python](https://img.shields.io/pypi/pyversions/django-envconfig)
![Django](https://img.shields.io/pypi/djversions/django-envconfig)
![License](https://img.shields.io/pypi/l/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 envvar is required (where `project_name` is the module originally
generated by `startproject`):
```sh
export DJANGO_PROJECT=project_name
```

The following envvars are also required (if `settings.py` is removed):
- `ALLOWED_HOSTS` (unless you set `DEBUG=on`)
- `DATABASES` *or* `PGDATABASE`

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.1/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.

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).



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ely-as/django-envconfig",
    "name": "django-envconfig",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Elyas Khan",
    "author_email": "mail@ely.as",
    "download_url": "https://files.pythonhosted.org/packages/51/93/46eb131cda53df96b3ab3f2bac351558fbbcf8d3e9948d0f64f88d0a9380/django-envconfig-0.1.2.tar.gz",
    "platform": "",
    "description": "# django-envconfig\n\n![Test](https://github.com/ely-as/django-envconfig/workflows/Test/badge.svg)\n![Python](https://img.shields.io/pypi/pyversions/django-envconfig)\n![Django](https://img.shields.io/pypi/djversions/django-envconfig)\n![License](https://img.shields.io/pypi/l/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 envvar is required (where `project_name` is the module originally\ngenerated by `startproject`):\n```sh\nexport DJANGO_PROJECT=project_name\n```\n\nThe following envvars are also required (if `settings.py` is removed):\n- `ALLOWED_HOSTS` (unless you set `DEBUG=on`)\n- `DATABASES` *or* `PGDATABASE`\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.1/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\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\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Configure Django using environment variables.",
    "version": "0.1.2",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "1c0a419ad34de65da523600a85e9b931",
                "sha256": "1e06ccb329089adee6d09771869226cbae03031dcd1aceebf4f38f65727ea64f"
            },
            "downloads": -1,
            "filename": "django_envconfig-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1c0a419ad34de65da523600a85e9b931",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 9815,
            "upload_time": "2020-11-22T04:01:23",
            "upload_time_iso_8601": "2020-11-22T04:01:23.163626Z",
            "url": "https://files.pythonhosted.org/packages/8d/3c/411a524e6936eeae91ec9b061821e7486eaf015a52c582e68d0fe696091a/django_envconfig-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "c39d2572e981c952acc3fb906648a808",
                "sha256": "99425a2f9e0eeef431a5e3ffa3f33011748a7f81e6c144e2b080a781d92c4ef3"
            },
            "downloads": -1,
            "filename": "django-envconfig-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "c39d2572e981c952acc3fb906648a808",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8407,
            "upload_time": "2020-11-22T04:01:24",
            "upload_time_iso_8601": "2020-11-22T04:01:24.361647Z",
            "url": "https://files.pythonhosted.org/packages/51/93/46eb131cda53df96b3ab3f2bac351558fbbcf8d3e9948d0f64f88d0a9380/django-envconfig-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-11-22 04:01:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "ely-as",
    "error": "Could not fetch GitHub repository",
    "lcname": "django-envconfig"
}
        
Elapsed time: 0.17668s