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.10-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for bear_config-1.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 cea11eefbcaec4227a9a64108a5ef9f37bce3703b02b05c552cb4ab065dbb59d
MD5 94476ad9003c594166bd9de09697d846
BLAKE2b-256 0b1b9014ca67ad22f0fe60fd2fcc6356657963253d6f7321cc7f97e423dc1377

See more details on using hashes here.

Provenance

The following attestation bundles were made for bear_config-1.0.10-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