How netherlandsforensicinstitute/confidence works
Project type and purpose
• It’s a Python configuration library (not a web or full-stack app).
• Purpose: load settings from YAML/JSON files, environment variables, default dicts, apply precedence, expose a read-only dict-like object with namespace support and value references.
File structure
Top-level directories and files:
• confidence/ – main package
– io.py (file and loader interfaces)
– models.py (Configuration class, namespace, resolution logic)
– utils.py (helpers: merging, precedence, reference resolution)
– exceptions.py (error classes)
• tests/ – unit tests covering each module
• docs/ – Sphinx docs (usage guides, API reference)
• .github/workflows – CI (tests & releases)
• pyproject.toml & pdm.lock – build & dependency config
Extract insights from the README
• Entry-point functions: loadf(), load_name(), Configuration(...) constructor.
• Features: multi-file loading, built-in load order (system vs. user), environment variable mapping, references, namespaces.
• Extensibility: users can plug in custom loaders or supply raw dicts.
Main components
A. Adapters / Input Sources
• File loaders (YAML, JSON) – in io.py
• Environment loader – built into loaders in io.py
• Literal dicts or custom sources – user-provided
B. Loader Registry & Precedence Engine
• loader chain orchestrator (defines load order, skips missing)
• implements Locality enum, loaders(...) factory
C. Merge & Resolution Core
• utils.merge / precedence logic – merges multiple maps in correct order
• reference resolver – replaces ${foo.bar} placeholders
D. Data Model
• Configuration class (models.py)
– wraps merged data
– implements attribute access, get(), namespaces, NotConfigured sentinel
E. Exception Handling
• exceptions.py – Invalid paths, circular references, loader failures
F. Consumer / Client
• Application code calling loadf(), load_name(), consuming Configuration API
Relationships & data flow
1) Client calls loadf() or load_name()
2) Input Sources → Adapter modules produce raw dicts
3) Loader Registry sequences these adapters based on precedence
4) Precedence Engine merges dicts into a single map
5) Reference Resolver walks the map, interpolates values
6) Configuration object is instantiated with final map
7) Client code queries Configuration via .get(), attribute access, or **kwargs unpacking
Architectural patterns
• Adapter pattern for source loaders
• Pipeline (chain of responsibility) for merging and resolution
• Facade (Configuration class exposes a simple API over internals)
• Sentinel (NotConfigured) for missing values