Skip to main content

AllConf - the All-Knowing Config Reader

PyPI

A configuration file reader for JSON and YAML with a bunch of nifty extras:

  • File inclusion and extension
  • Internal variable references
  • Fault-tolerant access to values that don't exist
  • Environment variable embedding (with defaults and "required" markers)
  • Python value embedding
  • On-demand external secret embedding via Fidelius (untested in this fork so far)
  • Single-file rendering of a parsed config (via CLI)
  • Python stub class generation for IDE completion (via CLI)

This is a fork of alviss, continued for development and support. A few names (notably the ALVISS_FIDELIUS_MODE environment variable) still carry the original project's name.

pip install allconf
pip install allconf[fidelius]   # optional, for secret lookup

TL;DR

Given this my_cfg.yaml:

app:
  name: MyApp
  environment: dev
  log_level: INFO

load and use it like this:

from allconf import quickloader

cfg = quickloader.autoload('my_cfg.yaml')

assert cfg.app.name == 'MyApp'
assert cfg.app.environment == 'dev'
assert cfg.app.log_level == 'INFO'

That's basically it!

Looking for a specific function? See the Public API index.

Features

Fault-tolerant access

Any value that isn't in the config reads as Empty (falsy), no matter how deeply nested, so there are no KeyErrors and no .get() chains:

cfg.app.timeout or 30            # 30 if not configured
cfg.does.not.exist.at.all        # Empty
cfg.app.timeout is Empty         # explicit check; `from allconf.structs import Empty`

File extension and inclusion

# prod.yaml
__extends__: base.yaml          # start from base.yaml; keys here override it
db:
  host: db.example.com
__include__: [logging.yaml]     # merge other files in

Both keys accept a single file or a list, can sit in any nested map, and resolve paths relative to the file they appear in. A dotted key such as a.b.c: 1 expands to nested maps.

Variable references

basics:
  env: dev
name: my-data-${basics.env}     # -> "my-data-dev"
basics_copy: ${basics}          # a lone reference keeps the original type

Environment variables

password: ${__ENV__:MY_PASS}                 # left as-is if unset
region: ${__ENV__:AWS_REGION=eu-west-1}      # with a default
api_key: ${__ENV__:API_KEY!=}                # required: loading raises if unset

A missing required variable raises AllConfSyntaxError (a ValueError).

Python values

version: ${__PY__:mypackage.__version__}
fallback: ${__PY__:maybe_missing.attr=1.0.0}   # default if the import fails

Secrets (Fidelius)

${__FID__:...} tags fetch secrets through the optional fidelius package. Behavior is chosen with the ALVISS_FIDELIUS_MODE environment variable (ON_DEMAND by default, ENABLED, DISABLED, SUBSTITUTE_ENV or MOCK) or a __fidelius__ key in the file. See the Public API index. This integration has not been re-tested since the fork.

Safe printing

print(cfg) and cfg.as_dict() mask string values whose key contains pass, secret, token or key. Pass unmaksed=True (sic) to as_dict(), as_json() or as_yaml() to get the real values.

Global config

from allconf.structs import SingletonConfig

cfg = SingletonConfig()
cfg.load(**quickloader.autoload('my_cfg.yaml').as_dict(unmaksed=True))
# Anywhere else in the program, SingletonConfig() is the same object

Subclass SingletonConfig to get a separate singleton per subclass. Use .update(...) to patch values and .load(...) to replace everything.

Command line tools

# Render a config, with all extends, includes and references resolved, to one file
allconf-render prod.yaml -o rendered.yaml

# Generate typed stub classes from a type descriptor file
allconf-stubber types.yaml -o cfg_stub.py

allconf-render leaves __ENV__, __FID__ and __PY__ expressions unresolved so the output can be resolved later (it was built to generate Kubernetes manifests). The stubber turns descriptor files such as

app:
  name: str*          # trailing * = required
  timeout: int|None

into BaseConfig subclasses, so that cfg: AllConfConfigStub = quickloader.autoload(...) gets IDE completion. Both tools take -f to overwrite output, -s for silent and -v for verbose. Details in the Public API index.

More documentation

Released under the MIT License.

Metadata

Release files for allconf 4.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for allconf 4.0.2
File Size Uploaded Provenance Actions
allconf-4.0.2.tar.gz 22.8 kB Without provenance Details for allconf-4.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for allconf 4.0.2
File Interpreter ABI Platform Actions
allconf-4.0.2-py3-none-any.whl Python 3 none any Details for allconf-4.0.2-py3-none-any.whl

Total release size: 50.2 kB

Release files / allconf-4.0.2.tar.gz

Download URL allconf-4.0.2.tar.gz
Size 22.8 kB
Tags Source
SHA-256 checksum
How to use checksums
642d53161c1d3677532976e4ee9a9854d8fdf8be2dfc66cfee1a3f349c60677e
BLAKE2b-256 checksum
How to use checksums
77144be97de77c8f442df7094bed702904b95ba4d55a151036173d57920a7c08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / allconf-4.0.2-py3-none-any.whl

Download URL allconf-4.0.2-py3-none-any.whl
Size 27.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b27f87085fd3ec0e37dbab0f07e1316d28dd818730fc73e606b155e16dd1de12
BLAKE2b-256 checksum
How to use checksums
d8c4438e39675cd57d78736e4213e7c4631e6cffce4f1664a45ad2aa7f2646e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for allconf 4.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

4.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page