https://github.com/shaneing/python-viper
Python configuration
https://github.com/shaneing/python-viper
config fire flags python viper
Last synced: 3 months ago
JSON representation
Python configuration
- Host: GitHub
- URL: https://github.com/shaneing/python-viper
- Owner: shaneing
- License: mit
- Created: 2020-01-13T15:41:54.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-27T14:02:07.000Z (over 6 years ago)
- Last Synced: 2026-01-02T15:51:40.567Z (6 months ago)
- Topics: config, fire, flags, python, viper
- Language: Python
- Homepage:
- Size: 17.6 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Python Viper
This project was inspired by [spf13/viper](https://github.com/spf13/viper).
## Installation
```
pip install py-viper
```
## Usage
```python
import tempfile
import viper
yaml_example = b'''
hello:
name: foo
'''
class Hello:
name = ''
class Config:
hello = Hello
if __name__ == '__main__':
with tempfile.NamedTemporaryFile(suffix='.yaml') as temp:
temp.write(yaml_example)
temp.seek(0)
viper.set_config_path(temp.name)
viper.read_config()
assert viper.get('hello.name') == 'foo'
conf = Config()
viper.unmarshal(conf)
assert conf.hello.name == 'foo'
```
You can also use remote config instead of local config:
```python
viper.set_config_type('yml')
viper.set_remote_provider('consul', '127.0.0.1', 8500, 'hello')
viper.read_remote_config()
```
Note:
- The config type only supports *yaml* or *yml*.
- The backend of remote config only supports *consul*.
## TODO
- [x] Read remote config
- [x] Unmarshal config
- [x] Add support for JSON