Skip to main content

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);
  • Backends evaluation order: precedence of the evaluation is directly set by the order of backends in Confita.backends list. The last not None 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


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)

Uploaded Source

Built Distribution

pyconfita-1.0.1-py3-none-any.whl (8.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page