env2dict


Nameenv2dict JSON
Version 0.0.5 PyPI version JSON
download
home_pagehttps://github.com/PasaOpasen/py-env-parser
SummaryEnvironment to python dictionary parser util
upload_time2024-07-22 09:54:58
maintainerDemetry Pascal
docs_urlNone
authorDemetry Pascal
requires_pythonNone
licenseMIT
keywords env environment
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![PyPI version](https://badge.fury.io/py/env2dict.svg)](https://pypi.org/project/env2dict/)
[![Downloads](https://pepy.tech/badge/env2dict)](https://pepy.tech/project/env2dict)
[![Downloads](https://pepy.tech/badge/env2dict/month)](https://pepy.tech/project/env2dict)
[![Downloads](https://pepy.tech/badge/env2dict/week)](https://pepy.tech/project/env2dict)

- [Environment to python dictionary parser util](#environment-to-python-dictionary-parser-util)
  - [About](#about)
  - [Syntax](#syntax)
  - [Examples](#examples)
  - [How to use](#how-to-use)
  - [More info](#more-info)


# Environment to python dictionary parser util

```sh
pip install env2dict
```

## About

This small package provides an ability of easy setting/overriding Python variables from environment. It is expected that u will use it to override your configuration data without changing configuration files itself, what is especially useful for containers-oriented applications.

## Syntax

To use it, u need to define environment variables matches the pattern: **Prefix***Body***OperationSuffix** where:
* **Prefix** is any word to determine target variables; for instance, `DD` prefix means to use only variables starts with `DD`; can be empty, what means to select all available variables (not recommended) 
* *Body* is the name of the target configuration parameter
* **OperationSuffix** is the one of next available suffixes (by default, but u can change your defaults):
  * `_NUMBER` to convert variable value to integer (environment variables are always strings)
  * `_FLOAT` to convert variable value to float
  * `_FLAG` to convert variable value to `optional[boolean]` at that values:
    *  `1`/`yes`/`Yes`/`True`/`true` equal `true`
    *  `0`/`no`/`No`/`False`/`false` equal `false`
    *  `None`/`null`/`NULL` equal `null`
  * `_LIST` means to parse variable value to string list
  * `_LIST_APPEND` means to parse variable value to string list and append to existing list instead of override
  * `_JSON` means to parse variable value as json string
  * no suffix means that no conversion will be performed, so variable value will stay a string

Moreover, u can put nested dicts values using `__` separator (or other on your choice) in the environment variable name.

Note also that u can combine these suffixes to perform more complicated transformations.

## Examples

* env variable `DD_S_COUNT_NUMBER=10` (with prefix `DD_` conversation) will be converted to `S_COUNT=10` Python object
* `DD_S_COUNT=10` 🠚 `S_COUNT="10"`
* `DD_USE_THIS_FLAG=yes` 🠚 `USE_THIS=True`
* `DD_USE_THIS_FLAG=true` 🠚 `USE_THIS=True`
* `DD_USE_THIS_FLAG=no` 🠚 `USE_THIS=False`
* `DD_ALLOWED_HOSTS_LIST_APPEND=127.0.0.1;dev.ocr.com;dev.web.com` will append a list `['127.0.0.1', 'dev.ocr.com', 'dev.web.com']` to `ALLOWED_HOSTS` variable
* `DD_READ_ME_JSON={\"a\": 1, \"b\": [1, 2]}` will be translated to `READ_ME={'a': 1, 'b': [1, 2]}`
* `DD_SOME_DICT__KEY1__KEY2=postgres` will create a dictionary `SOME_DICT={'KEY1': {'KEY2': 'postgres'}}` if it doesn't exist and will add a field in existing dictionary by aforementioned route
* `DD_A__B_LIST_APPEND_JSON=[1, 2, 3, [1, 2, \"3\"]]` will append `[1, 2, 3, [1, 2, "3"]]` to the end of value `V` from `A={"B": V}`

## How to use

```python
from env2dict import parse_vars

new_vars = parse_vars(
    prefix='DD_',
    initial_vars=None,
    source=None
)
```

## More info

Please take a look at: 
* `parse_vars` function docstring
* `tests` directory of this package repo.


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/PasaOpasen/py-env-parser",
    "name": "env2dict",
    "maintainer": "Demetry Pascal",
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "env, environment",
    "author": "Demetry Pascal",
    "author_email": "qtckpuhdsa@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/0f/a6/dd8c5165d2ab51fbdf52a7aa7211c2486dc4174bfca7e7c0d7184d12fea0/env2dict-0.0.5.tar.gz",
    "platform": null,
    "description": "[![PyPI version](https://badge.fury.io/py/env2dict.svg)](https://pypi.org/project/env2dict/)\n[![Downloads](https://pepy.tech/badge/env2dict)](https://pepy.tech/project/env2dict)\n[![Downloads](https://pepy.tech/badge/env2dict/month)](https://pepy.tech/project/env2dict)\n[![Downloads](https://pepy.tech/badge/env2dict/week)](https://pepy.tech/project/env2dict)\n\n- [Environment to python dictionary parser util](#environment-to-python-dictionary-parser-util)\n  - [About](#about)\n  - [Syntax](#syntax)\n  - [Examples](#examples)\n  - [How to use](#how-to-use)\n  - [More info](#more-info)\n\n\n# Environment to python dictionary parser util\n\n```sh\npip install env2dict\n```\n\n## About\n\nThis small package provides an ability of easy setting/overriding Python variables from environment. It is expected that u will use it to override your configuration data without changing configuration files itself, what is especially useful for containers-oriented applications.\n\n## Syntax\n\nTo use it, u need to define environment variables matches the pattern: **Prefix***Body***OperationSuffix** where:\n* **Prefix** is any word to determine target variables; for instance, `DD` prefix means to use only variables starts with `DD`; can be empty, what means to select all available variables (not recommended) \n* *Body* is the name of the target configuration parameter\n* **OperationSuffix** is the one of next available suffixes (by default, but u can change your defaults):\n  * `_NUMBER` to convert variable value to integer (environment variables are always strings)\n  * `_FLOAT` to convert variable value to float\n  * `_FLAG` to convert variable value to `optional[boolean]` at that values:\n    *  `1`/`yes`/`Yes`/`True`/`true` equal `true`\n    *  `0`/`no`/`No`/`False`/`false` equal `false`\n    *  `None`/`null`/`NULL` equal `null`\n  * `_LIST` means to parse variable value to string list\n  * `_LIST_APPEND` means to parse variable value to string list and append to existing list instead of override\n  * `_JSON` means to parse variable value as json string\n  * no suffix means that no conversion will be performed, so variable value will stay a string\n\nMoreover, u can put nested dicts values using `__` separator (or other on your choice) in the environment variable name.\n\nNote also that u can combine these suffixes to perform more complicated transformations.\n\n## Examples\n\n* env variable `DD_S_COUNT_NUMBER=10` (with prefix `DD_` conversation) will be converted to `S_COUNT=10` Python object\n* `DD_S_COUNT=10` \ud83e\udc1a `S_COUNT=\"10\"`\n* `DD_USE_THIS_FLAG=yes` \ud83e\udc1a `USE_THIS=True`\n* `DD_USE_THIS_FLAG=true` \ud83e\udc1a `USE_THIS=True`\n* `DD_USE_THIS_FLAG=no` \ud83e\udc1a `USE_THIS=False`\n* `DD_ALLOWED_HOSTS_LIST_APPEND=127.0.0.1;dev.ocr.com;dev.web.com` will append a list `['127.0.0.1', 'dev.ocr.com', 'dev.web.com']` to `ALLOWED_HOSTS` variable\n* `DD_READ_ME_JSON={\\\"a\\\": 1, \\\"b\\\": [1, 2]}` will be translated to `READ_ME={'a': 1, 'b': [1, 2]}`\n* `DD_SOME_DICT__KEY1__KEY2=postgres` will create a dictionary `SOME_DICT={'KEY1': {'KEY2': 'postgres'}}` if it doesn't exist and will add a field in existing dictionary by aforementioned route\n* `DD_A__B_LIST_APPEND_JSON=[1, 2, 3, [1, 2, \\\"3\\\"]]` will append `[1, 2, 3, [1, 2, \"3\"]]` to the end of value `V` from `A={\"B\": V}`\n\n## How to use\n\n```python\nfrom env2dict import parse_vars\n\nnew_vars = parse_vars(\n    prefix='DD_',\n    initial_vars=None,\n    source=None\n)\n```\n\n## More info\n\nPlease take a look at: \n* `parse_vars` function docstring\n* `tests` directory of this package repo.\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Environment to python dictionary parser util",
    "version": "0.0.5",
    "project_urls": {
        "Homepage": "https://github.com/PasaOpasen/py-env-parser"
    },
    "split_keywords": [
        "env",
        " environment"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "93ade2d5a3d7d51f22820e5661df77b4909b0798863a9c55fcc4db1d9a92d73d",
                "md5": "ed12c98352015bd8bcb095a78a56ad44",
                "sha256": "4dee48a83e5af3bafaa415a0d932805fab8919c4503866a2df68bc8a86b5fdcf"
            },
            "downloads": -1,
            "filename": "env2dict-0.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ed12c98352015bd8bcb095a78a56ad44",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6446,
            "upload_time": "2024-07-22T09:54:57",
            "upload_time_iso_8601": "2024-07-22T09:54:57.012566Z",
            "url": "https://files.pythonhosted.org/packages/93/ad/e2d5a3d7d51f22820e5661df77b4909b0798863a9c55fcc4db1d9a92d73d/env2dict-0.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0fa6dd8c5165d2ab51fbdf52a7aa7211c2486dc4174bfca7e7c0d7184d12fea0",
                "md5": "c05304fdf97e93789e05b5dd6e6f75a3",
                "sha256": "9d5aaa409c05207d67995d83693a0d07a5a479001c1101b5a8ffab58ad72801f"
            },
            "downloads": -1,
            "filename": "env2dict-0.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "c05304fdf97e93789e05b5dd6e6f75a3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6427,
            "upload_time": "2024-07-22T09:54:58",
            "upload_time_iso_8601": "2024-07-22T09:54:58.595266Z",
            "url": "https://files.pythonhosted.org/packages/0f/a6/dd8c5165d2ab51fbdf52a7aa7211c2486dc4174bfca7e7c0d7184d12fea0/env2dict-0.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-22 09:54:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "PasaOpasen",
    "github_project": "py-env-parser",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "env2dict"
}
        
Elapsed time: 0.30100s