Efficient environment variables management and typing for python.
Project description
[![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
```
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')
```
### 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"]'
```
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')]
```
### 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)
[![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
```
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')
```
### 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"]'
```
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')]
```
### 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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rhea-0.4.3.tar.gz
(14.2 kB
view details)
Built Distribution
rhea-0.4.3-py2.py3-none-any.whl
(12.2 kB
view details)
File details
Details for the file rhea-0.4.3.tar.gz
.
File metadata
- Download URL: rhea-0.4.3.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5dd72a481c78504c0c1a5555c1561b52bb2aad20e7057713a018c2a066330e4c |
|
MD5 | 9c56a0942027e01142a94a117d6cfcdf |
|
BLAKE2b-256 | d76a8810e9191c744c5bcb04152255c032f9440fbdf3d5ce9efaf69aef33e213 |
File details
Details for the file rhea-0.4.3-py2.py3-none-any.whl
.
File metadata
- Download URL: rhea-0.4.3-py2.py3-none-any.whl
- Upload date:
- Size: 12.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/3.6.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8c776b00e851204c005aa52b1429c4bf38e105a7de5f1aba0e9d2182dd78d18 |
|
MD5 | c0362fba2b8cb03fb56540b44c49fe88 |
|
BLAKE2b-256 | 122b65413c336993b17960155788c3277d9b71e5cdfbbc79a98672e0fbe5fcc1 |