Skip to main content

Confocal

A multi-layer configuration management library built on pydantic with source tracking and profile support.

Features

  • Hierarchical config file discovery (searches parent directories)
  • Profile support for different environments
  • Full source tracking to explain where each config value came from
  • Built on pydantic for robust validation and type safety
  • Rich terminal output for config inspection

Installation

pip install confocal

Quick Start

from confocal import BaseConfig
from pydantic import Field

class MyConfig(BaseConfig):
    database_url: str
    name: str = Field(default="Anonymous")
    debug: bool = False

# Load config from raiconfig.toml, environment variables, etc.
config = MyConfig.load()

# Show where config values came from
config.explain()

Config Sources (in order of precedence)

  1. Initialization arguments
  2. Environment variables
  3. Active profile from config file
  4. Config files (YAML or TOML)
  5. Default values

Using Config Files

Confocal supports both TOML and YAML config files. Specify which format to use in your config class:

Using TOML (default)

class MyConfig(BaseConfig):
    model_config = SettingsConfigDict(
        toml_file="config.toml",
    )

Using YAML

class MyConfig(BaseConfig):
    model_config = SettingsConfigDict(
        yaml_file="config.yaml",
    )

Using Profiles

Profile support works with both TOML and YAML files.

TOML example (raiconfig.toml):

database_url = "postgresql://prod-db:5432"

[profile.dev]
database_url = "postgresql://localhost:5432"
debug = true

[profile.test]
database_url = "postgresql://test-db:5432"

YAML example (config.yaml):

database_url: "postgresql://prod-db:5432"

profile:
  dev:
    database_url: "postgresql://localhost:5432"
    debug: true
  test:
    database_url: "postgresql://test-db:5432"

Activate a profile:

export ACTIVE_PROFILE=dev

YAML Environment Variables

YAML configs support environment variable substitution:

database_url: "{{ env_var('DB_URL', 'postgresql://localhost:5432') }}"
api_key: "{{ env_var('API_KEY') }}"  # Required, will error if not set

The shell-style ${VAR} syntax is also supported (in YAML and TOML):

database_url: "${DB_URL:-postgresql://localhost:5432}"  # With default
api_key: "${API_KEY}"  # Required, will error if not set
literal: "$${NOT_SUBSTITUTED}"  # Escape: becomes the literal text ${NOT_SUBSTITUTED}

Lines starting with # are not substituted.

Advanced Usage

Show full config inheritance chain:

config.explain(verbose=True)

Manually find nearest config file in parent directories:

from confocal import find_upwards
config_path = find_upwards("config.toml")

License

MIT

Metadata

Release files for confocal 0.3.0

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

Source distribution (sdist)

Source distribution for confocal 0.3.0
File Size Uploaded Provenance Actions
confocal-0.3.0.tar.gz 12.2 kB Without provenance Details for confocal-0.3.0.tar.gz

Built distribution (wheel)

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

Total release size: 26.2 kB

Release files / confocal-0.3.0.tar.gz

Download URL confocal-0.3.0.tar.gz
Size 12.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d5d1ff7048ba5a577a3d840daa1429f929d61b118bec774b86565df7f7232c5d
BLAKE2b-256 checksum
How to use checksums
04d69141529d2a68f5294414160ce3409b021eddff7370734c9da5ba4ab55e81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Release files / confocal-0.3.0-py3-none-any.whl

Download URL confocal-0.3.0-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
33fbc0584afc9b19532bda1e7c87dfd37f5bdbe9ff1eef2ccb743165e308e6aa
BLAKE2b-256 checksum
How to use checksums
9f3adbd9a7f1ec47f7d33ac0b4d43b3043b79881986616874b341b6f75da5d44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.17

Security for confocal 0.3.0

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.

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