PyConfita: Confita-like library for Python
Project description
PyConfita: Confita-like for Python
Library that ease loading a value from multiple key-value stores/backends with ordered evaluation.
Disclaimer
Free implementation of the GO library Confita.
Features
- Backends/stores supported:
- Environment variables (
EnvBackend
); - File (YAML format) (
FileBackend
); - Python dictionary object (
DictBackend
); - Vault key-value store (
VaultBackend
);
- Environment variables (
- Backends evaluation order: precedence of the evaluation is directly set by the order of backends in
Confita.backends
list. The last notNone
evaluated value is returned; - Explicit type casting supported for
str, bool, int, float
.
Quickstart
import os
from pyconfita import (
LoggingInterface,
Confita,
EnvBackend,
DictBackend
)
dumb_logger = LoggingInterface()
os.environ.setdefault("KEY", "VALUE_FROM_ENV")
c = Confita(
logger=dumb_logger,
backends=[
DictBackend({
"KEY": "VALUE",
"BOOL_1": "false",
"BOOL_2": "true"
}),
EnvBackend(),
],
)
assert c.get("KEY") == "VALUE_FROM_ENV" # Environment backend overrides previous backends' values
assert c.get("BOOL_1") == "false" # No implicit type conversion
assert c.get("BOOL_2", **{"type": bool}) # Explicit type conversion requested
c = Confita(
logger=dumb_logger,
backends=[
EnvBackend(),
DictBackend({"KEY": "VALUE"}),
],
)
assert c.get("KEY") == "VALUE" # Dict backend overrides previous backends' values
Tests
make test
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
pyconfita-1.0.1.tar.gz
(7.1 kB
view hashes)
Built Distribution
Close
Hashes for pyconfita-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37170161dd45885cd5a0bf087621928f56e1e74e33cc7a0ac936322ce3b26d75 |
|
MD5 | 25c87dfbe326e953544ce7c6c56b45f7 |
|
BLAKE2b-256 | 3fbd732f92cb524828830cb97f8412ece0e64a7c4ecadac5956b36398320bf43 |