Skip to main content

Multi-layer configuration management with source tracking

Project description

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

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

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

confocal-0.1.5.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

confocal-0.1.5-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file confocal-0.1.5.tar.gz.

File metadata

  • Download URL: confocal-0.1.5.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for confocal-0.1.5.tar.gz
Algorithm Hash digest
SHA256 35576e94ecd6751e034a7664590655619d1b44a6c1be4e53b2c82e9432ec5f7b
MD5 520e13f5f1e3ad87ef64031e600e6818
BLAKE2b-256 ba541e6afc6cba55c2d4d43c7f9ca6c8d3eb4c34b5828676a41b873aca1bbbc9

See more details on using hashes here.

File details

Details for the file confocal-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: confocal-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for confocal-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8e410ce0197eac1b2a8fdda28e99357f254805e6fceb5ef4fc5c90f878674782
MD5 fe082f9d16d993fa6be97c03f333b9f6
BLAKE2b-256 a7fb0641ec30d01c203db38aadfd3154ea61cc366bef2e2ab8149b90114f7dfb

See more details on using hashes here.

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