Skip to main content

Centralized YAML config loader with ease

Project description

yayaya

„Ja, ja, YAML schon wieder.“ — Every backend dev in Berlin, probably.

yayaya is a tiny helper for Yet Another YAml YArd (look, the letters lined up and we ran with it). It loads one YAML file—or several merged in order—lets you read nested keys with dot notation, and expands ${ENV_VAR} placeholders so secrets can live in the environment where they belong—not committed next to your instruction: prompts.

No framework. No magic beans. Just pyyaml and the sound of your PM saying jajaja when you tell them config is “basically done.”

Install

pip install yayaya

Or point pip at this repo if you live on the edge.

Quick start

from yayaya import init, get, contains

init("/path/to/config.yaml")

title = get("app.title", default="Untitled")
db_url = get("database.url", required=True)

if contains("features.experimental"):
    ...

Multiple files (layered config)

Pass a list: earlier files are the base, later ones override. Nested dicts are deep-merged; scalars and lists are replaced entirely by the newer file. Expansion runs once on the merged result.

init(["/etc/myapp/defaults.yaml", "/instance/config.yaml", "/instance/local.yaml"])

Useful for defaults + tenant config + secrets-by-path without copy-pasting huge trees.

${ENV_VAR} expansion

After parsing YAML, all strings are walked recursively. Placeholders like ${API_KEY} are replaced with values from os.environ. Missing variables become empty strings.

# config.yaml
service:
  api_key: "${API_KEY}"
  port: 8080
import os
from yayaya import init, get

os.environ["API_KEY"] = "secret"
init("config.yaml")
assert get("service.api_key") == "secret"
assert get("service.port") == 8080

You can also run expansion yourself (e.g. on a dict you built elsewhere):

from yayaya import expand_env_placeholders

data = expand_env_placeholders({"x": "${HOME}"}, environ=os.environ)

API

Function Purpose
init(path) Load one YAML file, or init([p1, p2, ...]) to merge left → right.
get(key, default=None, required=False) Dot-path lookup ("db.pool.size").
contains(key) Whether the path exists.
reload_config() Re-read the same path(s) in the same order.
override_config_path(path) Same as init (one path or a list).
config_paths() Absolute paths last passed to init / override_config_path.
deep_merge(a, b) Deep-merge two dict-like trees (lists replaced, not spliced).
expand_env_placeholders(value, environ=None) Recursive ${VAR} substitution.

Exceptions (all subclass ConfigError): ConfigNotLoadedError, ConfigFileNotFoundError, ConfigKeyNotFoundError.

Development

pip install -e ".[dev]"
python -m unittest discover -s tests -v

License

Whatever the repo owner says—ask Karel if you’re unsure.


If YAML were a conversation, yayaya is the part where you nod three times and actually read the file.

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

yayaya-0.3.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yayaya-0.3.0-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file yayaya-0.3.0.tar.gz.

File metadata

  • Download URL: yayaya-0.3.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for yayaya-0.3.0.tar.gz
Algorithm Hash digest
SHA256 8d1cde665bdc954a6027cc5abd217ebbeabb8cbdc59eb267f25afee76ad4d185
MD5 b9860b99a4726d8a7e9fc6b1e63d02c0
BLAKE2b-256 eb5a638f705fcef5baf04ae8a1283c4248d7f3e27ba5012aad1434e440ddb04e

See more details on using hashes here.

Provenance

The following attestation bundles were made for yayaya-0.3.0.tar.gz:

Publisher: publish.yml on KodzghlyCZ/python-yayaya

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file yayaya-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: yayaya-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for yayaya-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d626648e23b962a4f8596e2b71cc29398021e4832fd70bca6e44fe438b0ca776
MD5 2bd83edb5efea4382facc09e01700508
BLAKE2b-256 2536174b5298ca9230657e842fb9e04ad83a123d37b025fb339468ce1e39b83b

See more details on using hashes here.

Provenance

The following attestation bundles were made for yayaya-0.3.0-py3-none-any.whl:

Publisher: publish.yml on KodzghlyCZ/python-yayaya

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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