Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/riskiq/pyyamlcfg
Hierarchical YAML configuration utility for Python
https://github.com/riskiq/pyyamlcfg
Last synced: 4 months ago
JSON representation
Hierarchical YAML configuration utility for Python
- Host: GitHub
- URL: https://github.com/riskiq/pyyamlcfg
- Owner: RiskIQ
- License: other
- Created: 2015-03-12T23:16:35.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2019-04-08T08:04:52.000Z (almost 6 years ago)
- Last Synced: 2024-10-11T01:22:37.621Z (4 months ago)
- Language: Python
- Size: 184 KB
- Stars: 2
- Watchers: 9
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
yamlcfg
=======Hierarchical YAML configuration utility for Python
yamlcfg makes it easier to have different levels of YAML configuration files,
with prioritization that you declare, based on the order of the `paths`
keyword argument.It first checks your environment for the variable, and if it exists, it uses
that over anything else. Then it checks the first file in `paths`, or `path`,
and then the next in order until the variable is found. If not found, it returns
None.Access is allowed via normal attribute access via the dot operator, or from
an index such as `config['myattr']`.To dump the full configuration that was loaded back to file (first path in
`paths`), just invoke `write()`.Example:
from yamlcfg import YamlConfig
config = YamlConfig(path='~/.some_config.yml')
print(config.foo)
config.foo = 'bar'
config.write()fifo_configs = YamlConfig(paths=
('.myconfig.yml', '~/.userconfig.yml', '/etc/myconfig/defaultconfig.yml')
)
# First checks .myconfig.yml, and if it doesn't exist there, it checks
# ~/.userconfig.yml, and so on. If an environment variable of the same name
# is set, it will use that first.
print(fifo_configs.some_var)
# Dumps to the first path in paths, with every variable it found in order.
fifo_configs.write()