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

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.2.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.2.2
File Size Uploaded
confocal-0.2.2.tar.gz 11.8 kB Details

Built distribution (wheel)

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

Total release size: 25.5 kB

Release files / confocal-0.2.2.tar.gz

Download URL confocal-0.2.2.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
bb2fc3ea077b9bab96aacd6a6c4b4be6c1266e5bc6a1b49e6e61a451b0b97be0
BLAKE2b-256 checksum
How to use checksums
0a88188af5c78f9b322d7960ab39f50169f432803650ce5001d94d44735438f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

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

Download URL confocal-0.2.2-py3-none-any.whl
Size 13.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e9e2b2dc897db2a789bdeec9f2803c4fcbba2369f7b13be1f3b1980423bffb3f
BLAKE2b-256 checksum
How to use checksums
bb31c54d51eeee26a57be1abb0bc3e0accb3e5cad23006b2089d5191eeb70fe7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.9

2 release files

0.1.8

1 release file

0.1.7

1 release file

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.0

2 release files

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