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.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 confocal 0.3.2
File Size Uploaded Provenance Actions
confocal-0.3.2.tar.gz 12.6 kB Without provenance Details for confocal-0.3.2.tar.gz

Built distribution (wheel)

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

Total release size: 27.0 kB

Release files / confocal-0.3.2.tar.gz

Download URL confocal-0.3.2.tar.gz
Size 12.6 kB
Tags Source
SHA-256 checksum
How to use checksums
a39578c08dfc656c26600cc6d99ab01a467b794ecf83939db6469a904a23271a
BLAKE2b-256 checksum
How to use checksums
f5c561db8af92a7d4832ca91d314f0ba884036992606a4bc3274902092c90219
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.18

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

Download URL confocal-0.3.2-py3-none-any.whl
Size 14.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a3119272c61cb4a547089ecd1286f2f049b9291d7d8033c652e972b6479f9a90
BLAKE2b-256 checksum
How to use checksums
255a1498ae7c49e61f99f50bf78037eb36ad8f36174aa6b080301de0b49e931d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.18

Security for confocal 0.3.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.

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