🐱Make more easy for reading/validating/updating config for python app
Project description
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
# 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
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
catconfig-0.1.1.tar.gz
(4.4 kB
view details)
Built Distribution
File details
Details for the file catconfig-0.1.1.tar.gz
.
File metadata
- Download URL: catconfig-0.1.1.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.10 CPython/3.8.2 Linux/4.15.0-122-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 043ddd17c1372d530f046dea43f28ee3f6be9de454e781a1ab401b8f680beee0 |
|
MD5 | 09323b54cc6505002388e216109647e6 |
|
BLAKE2b-256 | 193a2fda7a122c51822c8bdc89f668248a288e31d5a275267bfea82d11d63122 |
File details
Details for the file catconfig-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: catconfig-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.10 CPython/3.8.2 Linux/4.15.0-122-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb91c5a794af773afc0ef897b7aa85dcb3276123289be10c08c3646b1558eedf |
|
MD5 | 4331762f7fc097031fba71906222f200 |
|
BLAKE2b-256 | f2309fd510a266814c19db31a19832e94b8320ca01932b7339e2903a0c4b0685 |