dict-like grouping of environment variables
Project description
# dict-envy
dict-like grouping of environment variables :sparkles:
---
Imagine you have this:
```
COUNTRIES_GB_NAME="United Kingdom"
COUNTRIES_GB_TLD=.uk
COUNTRIES_HK_NAME=China
COUNTRIES_HK_TLD=.cn
```
and with a simple call you can have all of this:
```python
>>> import os
>>> import dictenvy
>>> import pprint
>>> env = dictenvy.dictate(os.environ, depth=2)
>>> pprint.pprint(env)
{'countries': {'gb': {'name': 'United Kingdom', 'tld': '.uk'},
'hk': {'name': 'China', 'tld': '.cn'}}}
```
`depth` is how you regulate the depth of the returned dictionary.
<details><summary>Couple gotchas</summary>
### #1
Sometimes you may encounter the following situation:
```
TERM_PROGRAM=Apple_Terminal
TERM=xterm-256color
```
In which case, the return value would still be a dict, but `TERM` value would have an empty key like so:
```python
>>> import dictenvy
>>> import pprint
>>> env = dictenvy.dictate({'TERM': 'xterm-256color', 'TERM_PROGRAM': 'Apple_Terminal'}, depth=1))
>>> pprint.pprint(env)
{'term': {'': 'xterm-256color', 'program': 'Apple_Terminal'}}
```
### #2
Variables that start with an underscore will be left alone.
</details>
## Installation
Use pip:
```shell
$ pip install dict-envy
```
## License
MIT
dict-like grouping of environment variables :sparkles:
---
Imagine you have this:
```
COUNTRIES_GB_NAME="United Kingdom"
COUNTRIES_GB_TLD=.uk
COUNTRIES_HK_NAME=China
COUNTRIES_HK_TLD=.cn
```
and with a simple call you can have all of this:
```python
>>> import os
>>> import dictenvy
>>> import pprint
>>> env = dictenvy.dictate(os.environ, depth=2)
>>> pprint.pprint(env)
{'countries': {'gb': {'name': 'United Kingdom', 'tld': '.uk'},
'hk': {'name': 'China', 'tld': '.cn'}}}
```
`depth` is how you regulate the depth of the returned dictionary.
<details><summary>Couple gotchas</summary>
### #1
Sometimes you may encounter the following situation:
```
TERM_PROGRAM=Apple_Terminal
TERM=xterm-256color
```
In which case, the return value would still be a dict, but `TERM` value would have an empty key like so:
```python
>>> import dictenvy
>>> import pprint
>>> env = dictenvy.dictate({'TERM': 'xterm-256color', 'TERM_PROGRAM': 'Apple_Terminal'}, depth=1))
>>> pprint.pprint(env)
{'term': {'': 'xterm-256color', 'program': 'Apple_Terminal'}}
```
### #2
Variables that start with an underscore will be left alone.
</details>
## Installation
Use pip:
```shell
$ pip install dict-envy
```
## License
MIT
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
dict-envy-0.2.0.tar.gz
(2.5 kB
view details)
Built Distribution
File details
Details for the file dict-envy-0.2.0.tar.gz
.
File metadata
- Download URL: dict-envy-0.2.0.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e7ad15f380a8cb6ffa36384cd4cdfab70b50fd3a515aeb0bef32bdde0b25193 |
|
MD5 | 1dccac90ae922af363357444ab0f3526 |
|
BLAKE2b-256 | 9f8b3a42fc2e7302e1512b16a29b649d0adbbdcb13f281517c7249de49cc6bc5 |
File details
Details for the file dict_envy-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: dict_envy-0.2.0-py3-none-any.whl
- Upload date:
- Size: 2.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fceff87679a806f13952d56fdbc1bb197c850af4591c19b3643f8c85eb34344 |
|
MD5 | fc64b64d32ad504289b9128a736a273d |
|
BLAKE2b-256 | 37198fd01c3cfadb46a2c3ab308143a3e77d47199d96e5858295d88f71afdd02 |