https://github.com/dev-techmoe/python-catconfig
🐱Make more easy for reading/validating/updating config for python app
https://github.com/dev-techmoe/python-catconfig
config configuration-management json pypi python pythonmodule toml yaml
Last synced: 10 months ago
JSON representation
🐱Make more easy for reading/validating/updating config for python app
- Host: GitHub
- URL: https://github.com/dev-techmoe/python-catconfig
- Owner: dev-techmoe
- License: mit
- Created: 2020-10-19T10:46:59.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-10-28T07:39:47.000Z (about 5 years ago)
- Last Synced: 2025-02-04T11:43:18.022Z (10 months ago)
- Topics: config, configuration-management, json, pypi, python, pythonmodule, toml, yaml
- Language: Python
- Homepage:
- Size: 18.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CatConfig



🐱Make more easy for reading/validating/updating config for python app
## Install
```
pip install catconfig
```
If you want to use validation feature, install `cerberus` module for your project to use it normally.
Install `toml` or `pyyaml` module for toml/yaml format parsing.
## Quickstart
```python
# Example.py
from catconfig import CatConfig, ValidationError
# Load
# Load config from string
c = CatConfig()
c.load_from_string("""
{
"foo": "bar"
}
""")
# Load config when initalizing CatConfig object
c = CatConfig(data={
'foo': 'bar'
})
# load config from file
c = CatConfig()
c.load_from_file('./tests/assests/test.json')
# Specify config type when initalizing CatConfig object
c = CatConfig(format='json')
c.load_from_file('./tests/assests/test.json')
# Specify config type when loading config file
c = CatConfig()
c.load_from_file('./tests/assests/test.json', format='json')
# Get item
print(c.foo)
# Print: bar
print(bool(c.some.value.does.nt.exists))
# Print: False
print(str(c.some.value.does.nt.exists))
# Print: None
print(c['foo'])
# Print: bar
print(c.get('foo'))
# Print: bar
# Validation
# visit https://docs.python-cerberus.org/en/stable/usage.html for more info of schema
schema = {
'foo': {
'type': 'integer'
},
'some_field': {
'type': 'string'
}
}
c = CatConfig(validator_schema=schema)
try:
c.load_from_file('./tests/assests/test.json')
except ValidationError as err:
print(err.message)
# Print:
# arr: unknown field
# foo: must be of integer type
```
## License
MIT