rhea


Namerhea JSON
Version 0.5.5 PyPI version JSON
download
home_pagehttps://github.com/polyaxon/rhea
SummaryEfficient environment variables management and typing for python.
upload_time2019-11-15 11:54:00
maintainerMourad Mourafiq
docs_urlNone
authorMourad Mourafiq
requires_python
licenseMIT
keywords polyaxon dotenv environ environment env-vars .env django
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
[![Build Status](https://travis-ci.org/polyaxon/rhea.svg?branch=master)](https://travis-ci.org/polyaxon/rhea)
[![PyPI version](https://badge.fury.io/py/rhea.svg)](https://badge.fury.io/py/rhea)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/e49f4132c90e496e974d3e9883ee4d8c)](https://www.codacy.com/app/polyaxon/rhea?utm_source=github.com&utm_medium=referral&utm_content=polyaxon/rhea&utm_campaign=Badge_Grade)
[![Slack](https://img.shields.io/badge/chat-on%20slack-aadada.svg?logo=slack&longCache=true)](https://join.slack.com/t/polyaxon/shared_invite/enQtMzQ0ODc2MDg1ODc0LWY2ZTdkMTNmZjBlZmRmNjQxYmYwMTBiMDZiMWJhODI2ZTk0MDU4Mjg5YzA5M2NhYzc5ZjhiMjczMDllYmQ2MDg)

# rhea

Efficient environment variables management and typing for python.

## Installation

```
pip install -U rhea
```

## Features 

 * Typed retrieval of environment variables.
 * Handling of optional, secret, and local variables.
 * Reading from different sources: os, json files, yaml files.
 * Collection of parsed parameters.

## Usage

### Reading typed values from a params


```python
from rhea import Rhea

rhea_config = Rhea(bool_value1='1', 
                   bool_value2='false', 
                   bool_value3=True)

rhea_config.get_boolean('bool_value1')
# True

rhea_config.get_boolean('bool_value2')
# False

rhea_config.get_boolean('bool_value3')
# True
```

### Reading typed values from a env vars


```python
import os

from rhea import Rhea

rhea_config = Rhea.read_configs(os.environ)
```

### Reading typed values from different sources

```python
import os

from rhea import Rhea

rhea_config = Rhea.read_configs([os.environ, 
                                'json_file.json', 
                                'yaml_file.yaml',
                                'another_file_override.json',
                                {'foo': 'bar'}])
```

### Base types

examples:

```
BOOL_ENV_VALUE1: 1
BOOL_ENV_VALUE2: true
BOOL_ENV_VALUE3: f
BOOL_ENV_VALUE4: on

INT_ENV_VALUE1: '1' 
INT_ENV_VALUE2: -100

STRING_ENV_VALUE: 'some string'

FLOAT_ENV_VALUE1: '1.1'
FLOAT_ENV_VALUE2: -1.3
FLOAT_ENV_VALUE3: 1111.1
FLOAT_ENV_VALUE4: -33

DICT_ENV_VALUE: {"foo": "bar", "1": "2"}

LIST_ENV_VALUE: 'foo, bar, boo'

URI_ENV_VALUE1: user:pass@host.com
URI_ENV_VALUE2: user:pass@host:4000

AUTH_ENV_VALUE: user:pass
```

Reading:

```python
from rhea import Rhea

rhea_config = Rhea.read_configs([...])

rhea_config.get_boolean('BOOL_ENV_VALUE1')
# True
rhea_config.get_boolean('BOOL_ENV_VALUE2')
# True
rhea_config.get_boolean('BOOL_ENV_VALUE3')
# False
rhea_config.get_boolean('BOOL_ENV_VALUE4')
# True

rhea_config.get_int('INT_ENV_VALUE1')  
# 1
rhea_config.get_int('INT_ENV_VALUE2')  
# -100

rhea_config.get_string('STRING_ENV_VALUE')  
# some string

rhea_config.get_float('FLOAT_ENV_VALUE1')
# 1.1
rhea_config.get_float('FLOAT_ENV_VALUE1')
# -1.3
rhea_config.get_float('FLOAT_ENV_VALUE1')
# 1111.1
rhea_config.get_float('FLOAT_ENV_VALUE1')
# -33.0

rhea_config.get_dict('DICT_ENV_VALUE')
# {'foo': 'bar', '1': '2'}

rhea_config.get_list('LIST_ENV_VALUE')
# ['foo', 'bar', 'boo']

rhea_config.get_uri('URI_ENV_VALUE1')
# UriSpec('user', 'pass', 'host')

rhea_config.get_uri('URI_ENV_VALUE2')
# UriSpec('user', 'pass', 'host:4000')

rhea_config.get_uri('AUTH_ENV_VALUE')
# AuthSpec('user', 'pass')
```

### List of base types

examples:

```
BOOLS_ENV_VALUE: '[1, 0, "true", "false", "t", "f", "on", "off"]'
INTS_ENV_VALUE: '[1, 0, -100]'
STRINGS_ENV_VALUE: '["some_string", "another_string"]'
FLOATS_ENV_VALUE: '[1.1, -1.3, 0.03, 1111.1, 1.]'
DICTS_ENV_VALUE: '[{"foo": "bar", "1": 2}, {"foo": "bar", "1": 2}]'
DICT_OF_DICTS_ENV_VALUE: '{"key1": {"foo": "bar", "1": 2}, "key2": {"foo": "bar", "1": 2}}'
URIS_ENV_VALUE: '["user:pass@host.com", "user:pass@host:4000"]'
AUTHS_ENV_VALUE: '["user1:pass1", "user2:pass2"]'
```

Reading:

```python
from rhea import Rhea

rhea_config = Rhea.read_configs([...])

rhea_config.get_boolean('BOOLS_ENV_VALUE', is_list=True)
#  [True, False, True, False, True, False, True, False]

rhea_config.get_int('INTS_ENV_VALUE', is_list=True)
# [1, 0, -100]

rhea_config.get_string('STRINGS_ENV_VALUE', is_list=True)
# ['some_string', 'another_string']

rhea_config.get_float('FLOATS_ENV_VALUE', is_list=True)
# [1.1, -1.3, 0.03, 1111.1, 1.0]

rhea_config.get_dict('DICTS_ENV_VALUE', is_list=True)
# [{'foo1': 'bar1', '1': 2}, {'foo2': 'bar2', '3': 4}]

rhea_config.get_dict_of_dicts('DICT_OF_DICTS_ENV_VALUE')
# {'key1': {'foo': 'bar', '1': 2}, 'key2': {'foo': 'bar', '1': 2}}

rhea_config.get_uri('URIS_ENV_VALUE', is_list=True)
# [UriSpec('user', 'pass', 'host'), UriSpec('user', 'pass', 'host:4000')]

rhea_config.get_uri('AUTHS_ENV_VALUE', is_list=True)
# [UriSpec('user1', 'pass1'), UriSpec('user2', 'pass2')]
```

### Optional values and default values


```python
from rhea import Rhea

rhea_config = Rhea.read_configs([...])

rhea_config.get_boolean('BOOL_ENV_VALUE', is_optional=True)
# None
rhea_config.get_boolean('BOOL_ENV_VALUE', is_optional=True, default=True)
# True

rhea_config.get_int('INT_ENV_VALUE', is_optional=True)
# None
rhea_config.get_int('INT_ENV_VALUE', is_optional=True, default=101)
# 101

rhea_config.get_float('FLOAT_ENV_VALUE', is_optional=True)
# None
rhea_config.get_float('FLOAT_ENV_VALUE', is_optional=True, default=-3.3)
# -3.3

rhea_config.get_float('STRING_ENV_VALUE', is_optional=True)
# None
rhea_config.get_float('STRING_ENV_VALUE', is_optional=True, default='default')
# default
```

### Value validation


```python
from rhea import Rhea

rhea_config = Rhea.read_configs([...])


# INT_ENV_VALUE = 11
rhea_config.get_int('INT_ENV_VALUE', options=[1, 2, 3])
# raise RheaError
rhea_config.get_int('INT_ENV_VALUE', options=[1, 2, 3, 11])
# 11
```

### Parsed data


```python
from rhea import Rhea

rhea_config = Rhea.read_configs([...])

rhea_config.get_requested_data(include_locals=False, include_secrets=False)
# {'key1': 'value1', ...}
```

## Example with Django

```python
from rhea import Rhea

rhea_config = Rhea.read_configs([...])

DEBUG = rhea_config.get_boolean('DJANGO_DEBUG_MODE', is_optional=True, default=False)
SECRET_KEY = rhea_config.get_string('POLYAXON_SECRET_KEY', is_secret=True)
```

## Running tests

```
pytest
```

# License

[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fpolyaxon%2Frhea.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fpolyaxon%2Frhea?ref=badge_large)



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/polyaxon/rhea",
    "name": "rhea",
    "maintainer": "Mourad Mourafiq",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "mourad.mourafiq@gmail.com",
    "keywords": "polyaxon,dotenv,environ,environment,env-vars,.env,django",
    "author": "Mourad Mourafiq",
    "author_email": "mourad.mourafiq@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/7a/7a/634aaa4f5b7ed0b98462e295f7cbb625faa13dd9c1ca47feb5ea5d3a288b/rhea-0.5.5.tar.gz",
    "platform": "any",
    "description": "[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)\n[![Build Status](https://travis-ci.org/polyaxon/rhea.svg?branch=master)](https://travis-ci.org/polyaxon/rhea)\n[![PyPI version](https://badge.fury.io/py/rhea.svg)](https://badge.fury.io/py/rhea)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/e49f4132c90e496e974d3e9883ee4d8c)](https://www.codacy.com/app/polyaxon/rhea?utm_source=github.com&utm_medium=referral&utm_content=polyaxon/rhea&utm_campaign=Badge_Grade)\n[![Slack](https://img.shields.io/badge/chat-on%20slack-aadada.svg?logo=slack&longCache=true)](https://join.slack.com/t/polyaxon/shared_invite/enQtMzQ0ODc2MDg1ODc0LWY2ZTdkMTNmZjBlZmRmNjQxYmYwMTBiMDZiMWJhODI2ZTk0MDU4Mjg5YzA5M2NhYzc5ZjhiMjczMDllYmQ2MDg)\n\n# rhea\n\nEfficient environment variables management and typing for python.\n\n## Installation\n\n```\npip install -U rhea\n```\n\n## Features \n\n * Typed retrieval of environment variables.\n * Handling of optional, secret, and local variables.\n * Reading from different sources: os, json files, yaml files.\n * Collection of parsed parameters.\n\n## Usage\n\n### Reading typed values from a params\n\n\n```python\nfrom rhea import Rhea\n\nrhea_config = Rhea(bool_value1='1', \n                   bool_value2='false', \n                   bool_value3=True)\n\nrhea_config.get_boolean('bool_value1')\n# True\n\nrhea_config.get_boolean('bool_value2')\n# False\n\nrhea_config.get_boolean('bool_value3')\n# True\n```\n\n### Reading typed values from a env vars\n\n\n```python\nimport os\n\nfrom rhea import Rhea\n\nrhea_config = Rhea.read_configs(os.environ)\n```\n\n### Reading typed values from different sources\n\n```python\nimport os\n\nfrom rhea import Rhea\n\nrhea_config = Rhea.read_configs([os.environ, \n                                'json_file.json', \n                                'yaml_file.yaml',\n                                'another_file_override.json',\n                                {'foo': 'bar'}])\n```\n\n### Base types\n\nexamples:\n\n```\nBOOL_ENV_VALUE1: 1\nBOOL_ENV_VALUE2: true\nBOOL_ENV_VALUE3: f\nBOOL_ENV_VALUE4: on\n\nINT_ENV_VALUE1: '1' \nINT_ENV_VALUE2: -100\n\nSTRING_ENV_VALUE: 'some string'\n\nFLOAT_ENV_VALUE1: '1.1'\nFLOAT_ENV_VALUE2: -1.3\nFLOAT_ENV_VALUE3: 1111.1\nFLOAT_ENV_VALUE4: -33\n\nDICT_ENV_VALUE: {\"foo\": \"bar\", \"1\": \"2\"}\n\nLIST_ENV_VALUE: 'foo, bar, boo'\n\nURI_ENV_VALUE1: user:pass@host.com\nURI_ENV_VALUE2: user:pass@host:4000\n\nAUTH_ENV_VALUE: user:pass\n```\n\nReading:\n\n```python\nfrom rhea import Rhea\n\nrhea_config = Rhea.read_configs([...])\n\nrhea_config.get_boolean('BOOL_ENV_VALUE1')\n# True\nrhea_config.get_boolean('BOOL_ENV_VALUE2')\n# True\nrhea_config.get_boolean('BOOL_ENV_VALUE3')\n# False\nrhea_config.get_boolean('BOOL_ENV_VALUE4')\n# True\n\nrhea_config.get_int('INT_ENV_VALUE1')  \n# 1\nrhea_config.get_int('INT_ENV_VALUE2')  \n# -100\n\nrhea_config.get_string('STRING_ENV_VALUE')  \n# some string\n\nrhea_config.get_float('FLOAT_ENV_VALUE1')\n# 1.1\nrhea_config.get_float('FLOAT_ENV_VALUE1')\n# -1.3\nrhea_config.get_float('FLOAT_ENV_VALUE1')\n# 1111.1\nrhea_config.get_float('FLOAT_ENV_VALUE1')\n# -33.0\n\nrhea_config.get_dict('DICT_ENV_VALUE')\n# {'foo': 'bar', '1': '2'}\n\nrhea_config.get_list('LIST_ENV_VALUE')\n# ['foo', 'bar', 'boo']\n\nrhea_config.get_uri('URI_ENV_VALUE1')\n# UriSpec('user', 'pass', 'host')\n\nrhea_config.get_uri('URI_ENV_VALUE2')\n# UriSpec('user', 'pass', 'host:4000')\n\nrhea_config.get_uri('AUTH_ENV_VALUE')\n# AuthSpec('user', 'pass')\n```\n\n### List of base types\n\nexamples:\n\n```\nBOOLS_ENV_VALUE: '[1, 0, \"true\", \"false\", \"t\", \"f\", \"on\", \"off\"]'\nINTS_ENV_VALUE: '[1, 0, -100]'\nSTRINGS_ENV_VALUE: '[\"some_string\", \"another_string\"]'\nFLOATS_ENV_VALUE: '[1.1, -1.3, 0.03, 1111.1, 1.]'\nDICTS_ENV_VALUE: '[{\"foo\": \"bar\", \"1\": 2}, {\"foo\": \"bar\", \"1\": 2}]'\nDICT_OF_DICTS_ENV_VALUE: '{\"key1\": {\"foo\": \"bar\", \"1\": 2}, \"key2\": {\"foo\": \"bar\", \"1\": 2}}'\nURIS_ENV_VALUE: '[\"user:pass@host.com\", \"user:pass@host:4000\"]'\nAUTHS_ENV_VALUE: '[\"user1:pass1\", \"user2:pass2\"]'\n```\n\nReading:\n\n```python\nfrom rhea import Rhea\n\nrhea_config = Rhea.read_configs([...])\n\nrhea_config.get_boolean('BOOLS_ENV_VALUE', is_list=True)\n#  [True, False, True, False, True, False, True, False]\n\nrhea_config.get_int('INTS_ENV_VALUE', is_list=True)\n# [1, 0, -100]\n\nrhea_config.get_string('STRINGS_ENV_VALUE', is_list=True)\n# ['some_string', 'another_string']\n\nrhea_config.get_float('FLOATS_ENV_VALUE', is_list=True)\n# [1.1, -1.3, 0.03, 1111.1, 1.0]\n\nrhea_config.get_dict('DICTS_ENV_VALUE', is_list=True)\n# [{'foo1': 'bar1', '1': 2}, {'foo2': 'bar2', '3': 4}]\n\nrhea_config.get_dict_of_dicts('DICT_OF_DICTS_ENV_VALUE')\n# {'key1': {'foo': 'bar', '1': 2}, 'key2': {'foo': 'bar', '1': 2}}\n\nrhea_config.get_uri('URIS_ENV_VALUE', is_list=True)\n# [UriSpec('user', 'pass', 'host'), UriSpec('user', 'pass', 'host:4000')]\n\nrhea_config.get_uri('AUTHS_ENV_VALUE', is_list=True)\n# [UriSpec('user1', 'pass1'), UriSpec('user2', 'pass2')]\n```\n\n### Optional values and default values\n\n\n```python\nfrom rhea import Rhea\n\nrhea_config = Rhea.read_configs([...])\n\nrhea_config.get_boolean('BOOL_ENV_VALUE', is_optional=True)\n# None\nrhea_config.get_boolean('BOOL_ENV_VALUE', is_optional=True, default=True)\n# True\n\nrhea_config.get_int('INT_ENV_VALUE', is_optional=True)\n# None\nrhea_config.get_int('INT_ENV_VALUE', is_optional=True, default=101)\n# 101\n\nrhea_config.get_float('FLOAT_ENV_VALUE', is_optional=True)\n# None\nrhea_config.get_float('FLOAT_ENV_VALUE', is_optional=True, default=-3.3)\n# -3.3\n\nrhea_config.get_float('STRING_ENV_VALUE', is_optional=True)\n# None\nrhea_config.get_float('STRING_ENV_VALUE', is_optional=True, default='default')\n# default\n```\n\n### Value validation\n\n\n```python\nfrom rhea import Rhea\n\nrhea_config = Rhea.read_configs([...])\n\n\n# INT_ENV_VALUE = 11\nrhea_config.get_int('INT_ENV_VALUE', options=[1, 2, 3])\n# raise RheaError\nrhea_config.get_int('INT_ENV_VALUE', options=[1, 2, 3, 11])\n# 11\n```\n\n### Parsed data\n\n\n```python\nfrom rhea import Rhea\n\nrhea_config = Rhea.read_configs([...])\n\nrhea_config.get_requested_data(include_locals=False, include_secrets=False)\n# {'key1': 'value1', ...}\n```\n\n## Example with Django\n\n```python\nfrom rhea import Rhea\n\nrhea_config = Rhea.read_configs([...])\n\nDEBUG = rhea_config.get_boolean('DJANGO_DEBUG_MODE', is_optional=True, default=False)\nSECRET_KEY = rhea_config.get_string('POLYAXON_SECRET_KEY', is_secret=True)\n```\n\n## Running tests\n\n```\npytest\n```\n\n# License\n\n[![FOSSA Status](https://app.fossa.io/api/projects/git%2Bgithub.com%2Fpolyaxon%2Frhea.svg?type=large)](https://app.fossa.io/projects/git%2Bgithub.com%2Fpolyaxon%2Frhea?ref=badge_large)\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Efficient environment variables management and typing for python.",
    "version": "0.5.5",
    "project_urls": {
        "Homepage": "https://github.com/polyaxon/rhea"
    },
    "split_keywords": [
        "polyaxon",
        "dotenv",
        "environ",
        "environment",
        "env-vars",
        ".env",
        "django"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0f569a7ab05d4858c8c0ac000787236d812fe0d35fa0a2160e099aedbf67b1f1",
                "md5": "52d244942fdfd2dc06f70229f9bbe09f",
                "sha256": "f1616136f21be266873f131dff7aca599c71fba4042c9dece2ea4e79925b2b50"
            },
            "downloads": -1,
            "filename": "rhea-0.5.5-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "52d244942fdfd2dc06f70229f9bbe09f",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 18129,
            "upload_time": "2019-11-15T11:53:58",
            "upload_time_iso_8601": "2019-11-15T11:53:58.967830Z",
            "url": "https://files.pythonhosted.org/packages/0f/56/9a7ab05d4858c8c0ac000787236d812fe0d35fa0a2160e099aedbf67b1f1/rhea-0.5.5-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7a7a634aaa4f5b7ed0b98462e295f7cbb625faa13dd9c1ca47feb5ea5d3a288b",
                "md5": "a34d7c747e7e90c812450c4eccc91d42",
                "sha256": "323faf9245f7208bb8fcd6d6033820c1a23c1841b944d4198d903396373b7215"
            },
            "downloads": -1,
            "filename": "rhea-0.5.5.tar.gz",
            "has_sig": false,
            "md5_digest": "a34d7c747e7e90c812450c4eccc91d42",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 19083,
            "upload_time": "2019-11-15T11:54:00",
            "upload_time_iso_8601": "2019-11-15T11:54:00.807638Z",
            "url": "https://files.pythonhosted.org/packages/7a/7a/634aaa4f5b7ed0b98462e295f7cbb625faa13dd9c1ca47feb5ea5d3a288b/rhea-0.5.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2019-11-15 11:54:00",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "polyaxon",
    "github_project": "rhea",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "rhea"
}
        
Elapsed time: 0.10059s