Skip to main content

Pydantic-powered config management

Project description

Pattern Agentic Settings

A settings class based on pydantic-settings that facilitates:

  • printing all settings on startup (redacts senstive attrs)
  • easy loading of .env files via an env variable
  • optionally load app version from importlib (sourced from pyproject.toml)
  • optional hot reload using watchfiles

Installation

pip install pattern_agentic_settings[hotreload]

Note that without the hotreload extension:

pip install pattern_agentic_settings

watchfiles is not pulled in, and dot envs will not auto-reload.

Example

class Settings(PABaseSettings):
    model_config = SettingsConfigDict(
        env_prefix="MYAPP_"
    )
    worker_count: int

# expects MYAPP_WORKER_COUNT 
# if MYAPP_DOT_ENV points to a file, will try to load vars from it
# throws an error if not defined
settings = Settings.load('my_app')

# This will watch the env file on disk and reload values if it changes
# This must be called in the context of an existing async runloop
# it also requires the hotreload extension (see Installation)

settings.watch_env_file()

Exepcted output:

My App v1.0.0
Configuration:
  WORKER_COUNT: 3

And on failure:

RuntimeError: Configuration validation failed:

      Missing required configuration fields:
        - worker_count

Tests

To run the tests the package must be installed in edit mode:

uv pip install -e .

# or to test hotreload
uv pip install -e .[hotreload]

After that:

# Base test
uv run pytest tests/test_base.py

# All tests
uv run pytest

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

pattern_agentic_settings-2.0.0.dev0.tar.gz (49.0 kB view details)

Uploaded Source

Built Distribution

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

pattern_agentic_settings-2.0.0.dev0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file pattern_agentic_settings-2.0.0.dev0.tar.gz.

File metadata

File hashes

Hashes for pattern_agentic_settings-2.0.0.dev0.tar.gz
Algorithm Hash digest
SHA256 efc68c18fd98045b855ba2201d274e50cb8ef27b658caa9384dccaae289e5dc2
MD5 b1ee733c111334da999a7628ad49f31d
BLAKE2b-256 05eaeae7fb9d316310482f834ef82e1ad53307caa343f7dc3644bfc2b460a4fb

See more details on using hashes here.

File details

Details for the file pattern_agentic_settings-2.0.0.dev0-py3-none-any.whl.

File metadata

File hashes

Hashes for pattern_agentic_settings-2.0.0.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 00b0c469cb62af2d9fbc6ebd61c156a191554bf6099b684cf328c27d2c9600ad
MD5 fc2d917fc5811c39c26662138b9debaf
BLAKE2b-256 67ab6de6409cf1d64a14c9dac541b1ed8fef41c8ccacdeb18d1f026dd7810870

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