https://github.com/ibm/alchemy-config
The aconfig library supports yaml-based configuration files with environment-variable overrides in python
https://github.com/ibm/alchemy-config
configuration python yaml yaml-configuration
Last synced: about 1 year ago
JSON representation
The aconfig library supports yaml-based configuration files with environment-variable overrides in python
- Host: GitHub
- URL: https://github.com/ibm/alchemy-config
- Owner: IBM
- License: mit
- Created: 2021-08-19T15:01:49.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-10-30T15:05:04.000Z (over 1 year ago)
- Last Synced: 2025-04-24T03:07:58.043Z (about 1 year ago)
- Topics: configuration, python, yaml, yaml-configuration
- Language: Python
- Homepage:
- Size: 40 KB
- Stars: 0
- Watchers: 5
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Alchemy Config
The `aconfig` library provides simple `yaml` configuration in `python` with environment-based overrides.
## Library advantages
1. Easily reads environment variables with error handling, e.g. for absence of variables or boolean capitalization
1. Allows users to easily access and traverse nested configuration without checking for key presence on every access
1. Automatically handles overriding logic - environment variables take precedence over local configuration files
## Installation
To install, simply use `pip`
```sh
pip install alchemy-config
```
## Quick Start
**config.yaml**
```yaml
foo: 1
bar:
baz: "bat"
```
**main.py**
```py
import aconfig
if __name__ == "__main__":
config = aconfig.Config.from_yaml("config.yaml")
print(config.foo)
print(config.bar.baz)
```
```sh
export BAR_BAZ="buz"
python3 main.py
```
## Corner-case Behavior
You CAN set builtin method names as attributes on the `config`. However, you should only access/delete them via dictionary access methods.
For example:
```py
import aconfig
cfg = {"update": True}
config = aconfig.Config(cfg)
# DO NOT DO THIS:
config.update
# DO THIS INSTEAD:
config["update"]
```
This is because there is no way in Python to tell whether you want the method or the attribute `"update"` when "getting" it from the object.