https://github.com/reorx/getenv
Environment variable definition with type
https://github.com/reorx/getenv
definition environment python validator
Last synced: 8 days ago
JSON representation
Environment variable definition with type
- Host: GitHub
- URL: https://github.com/reorx/getenv
- Owner: reorx
- Created: 2016-09-21T11:02:28.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-03-24T17:26:24.000Z (about 5 years ago)
- Last Synced: 2025-03-28T21:01:42.991Z (25 days ago)
- Topics: definition, environment, python, validator
- Language: Python
- Homepage:
- Size: 5.86 KB
- Stars: 7
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# getenv
Environment variable definition with type.
## Install
```bash
pip install getenv
```## Usage
See `example.py`:
```python
from getenv import Envapp_name = 'FOO'
# Set the prefix for env vars
Env.set_prefix(app_name)# Define your envs
ENV_PROCESSES = Env('{prefix}_PROCESSES', type=int, default=1)
ENV_DEBUG = Env('{prefix}_DEBUG', type=bool, default=False)
ENV_OPERATOR = Env('{prefix}_OPERATOR', default=None)def main():
processes = ENV_PROCESSES.get()
debug = ENV_DEBUG.get()
operator = ENV_OPERATOR.get()print('Run {} processes, debug = {}, operator = {}'.format(processes, debug, operator))
```Run `example.py` normally:
```bash
$ FOO_PROCESSES=3 python example.py
Run 3 processes, debug = False, operator = None
```Then with envs:
```bash
$ FOO_PROCESSES=3 FOO_DEBUG=true FOO_OPERATOR=$(whoami) python example.py
Run 3 processes, debug = True, operator = reorx
```