Skip to main content

A useful Pydantic based config system with various options

Project description

Bear Config

pypi version

A useful Pydantic based config system with various options

Installation

With uv: uv tool install bear-config

Configuration precedence

Values are merged in order; later sources override earlier ones:

  1. default.toml
  2. {env}.toml (for the active environment, e.g., dev.toml, prod.toml)
  3. local.toml
  4. Environment variables prefixed with your program name (e.g., MY_APP_...)

Search paths (by default): ~/.config/{program}/ and ./config/{program}/.

Quickstart

Define a Pydantic model for your settings, then load it with the ConfigManager.

from pydantic import BaseModel
from bear_config.config_manager import ConfigManager


class Database(BaseModel):
    host: str = "localhost"
    port: int = 5432


class Settings(BaseModel):
    database: Database = Database()
    debug: bool = False


config = ConfigManager[Settings](
    config_model=Settings,
    program_name="my_app",
    env="dev",
).config

print(config.database.host)
print(config.debug)

Environment variables can override nested keys using the program prefix. For example, MY_APP_DATABASE_HOST=prod.db and MY_APP_DEBUG=true will replace the corresponding fields after files are loaded.

Generating a default config

You can scaffold a TOML file with the model’s default values:

from bear_config.config_manager import ConfigManager

config_mgr = ConfigManager[Settings](Settings, program_name="my_app")
config_mgr.create_default_config()  # writes default.toml into the local config dir

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

bear_config-1.0.9-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file bear_config-1.0.9-py3-none-any.whl.

File metadata

  • Download URL: bear_config-1.0.9-py3-none-any.whl
  • Upload date:
  • Size: 19.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for bear_config-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 29cd1f034c75a1cf324328c8c6405b83ac4a595e616bfa3c173459f0302200ff
MD5 dab6f5573d74023f4e15435885c6ab6d
BLAKE2b-256 f2174ca96225d7d266a6bdc2cdfad44b1f101069af566cace33fad3769f57530

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_config-1.0.9-py3-none-any.whl:

Publisher: build-wheels.yml on sicksubroutine/bear-config

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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