Skip to main content

A library for managing Pydantic settings objects

Project description

pydantic-settings-manager

A library for managing Pydantic settings objects.

Features

  • Two types of settings managers:
    • SingleSettingsManager: For managing a single settings object
    • MappedSettingsManager: For managing multiple settings objects mapped to keys
  • Support for loading settings from multiple sources
  • Command line argument overrides
  • Settings validation through Pydantic
  • Type hints and documentation

Installation

pip install pydantic-settings-manager

Quick Start

Single Settings Manager

from pydantic_settings import BaseSettings
from pydantic_settings_manager import SingleSettingsManager

class MySettings(BaseSettings):
    name: str = "default"
    value: int = 0

# Create a settings manager
manager = SingleSettingsManager(MySettings)

# Update settings from a configuration file
manager.user_config = {"name": "from_file", "value": 42}

# Update settings from command line arguments
manager.cli_args = {"value": 100}

# Get the current settings (combines both sources)
settings = manager.settings
assert settings.name == "from_file"  # from user_config
assert settings.value == 100  # from cli_args (overrides user_config)

Mapped Settings Manager

from pydantic_settings import BaseSettings
from pydantic_settings_manager import MappedSettingsManager

class MySettings(BaseSettings):
    name: str = "default"
    value: int = 0

# Create a settings manager
manager = MappedSettingsManager(MySettings)

# Set up multiple configurations
manager.user_config = {
    "map": {
        "dev": {"name": "development", "value": 42},
        "prod": {"name": "production", "value": 100}
    }
}

# Select which configuration to use
manager.set_cli_args("dev")

# Get the current settings
settings = manager.settings
assert settings.name == "development"
assert settings.value == 42

# Switch to a different configuration
manager.set_cli_args("prod")
settings = manager.settings
assert settings.name == "production"
assert settings.value == 100

Development

This project uses modern Python development tools with flexible dependency groups:

  • ruff: Fast linter and formatter (replaces black, isort, and flake8)
  • mypy: Static type checking
  • pytest: Testing framework with coverage reporting
  • uv: Fast Python package manager with PEP 735 dependency groups support

Setup

# Install all development dependencies
uv sync --group dev

# Or install specific dependency groups
uv sync --group test    # Testing tools only
uv sync --group lint    # Linting tools only

# Format code
uv run ruff check --fix .

# Run linting
uv run ruff check .
uv run mypy .

# Run tests
uv run pytest --cov=pydantic_settings_manager tests/

# Build and test everything
make build

Development Workflow

# Quick setup for testing
uv sync --group test
make test

# Quick setup for linting
uv sync --group lint
make lint

# Full development environment
uv sync --group dev
make build

Documentation

For more detailed documentation, please see the GitHub repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

pydantic_settings_manager-0.2.0.tar.gz (39.2 kB view details)

Uploaded Source

Built Distribution

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

pydantic_settings_manager-0.2.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_settings_manager-0.2.0.tar.gz.

File metadata

File hashes

Hashes for pydantic_settings_manager-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ea1f7a58663395dfe70f15ac202bc84cbd2c2a1a1c262f5f34cd1bc5c8b5b6aa
MD5 f321b231564425c5105e704e323ec795
BLAKE2b-256 b5cc2811df1cc7c4fe6b487b7fbb87dfafe34c4d26c395bcfb9f73eaf1327822

See more details on using hashes here.

File details

Details for the file pydantic_settings_manager-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pydantic_settings_manager-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8ad61456839a1890e2a3fb4cc6a9dddd7cc78a84aa342536ea23532485407d7a
MD5 040d24bb7132f90c27910ebd2d859b33
BLAKE2b-256 512d3a61976e6de54a716c102d6bcb87bbf4a43af73f55fa0017be9550d506b7

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