Skip to main content

A useful Pydantic based config system with various options

Reason this release was yanked:

doesn't work on windows

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: bear_config-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 18.6 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 52bbaed98070e3e498f193c37d5cff99bc37c2eccaf051a3b512da540250cd31
MD5 b0e85c1028bead80f4160e68d1c959a3
BLAKE2b-256 69d921763195bf8efb3699b9c6568aabb949430720aa7f9eaab10c8cfb7d80c0

See more details on using hashes here.

Provenance

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