pydantic-settings-manager


Namepydantic-settings-manager JSON
Version 0.1.2 PyPI version JSON
download
home_pagehttps://github.com/kiarina/pydantic-settings-manager
SummaryA library for managing Pydantic settings objects
upload_time2024-12-12 03:39:48
maintainerNone
docs_urlNone
authorkiarina
requires_python<4.0,>=3.8
licenseMIT
keywords pydantic settings configuration
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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

```bash
pip install pydantic-settings-manager
```

## Quick Start

### Single Settings Manager

```python
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

```python
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
```

## Documentation

For more detailed documentation, please see the [GitHub repository](https://github.com/kiarina/pydantic-settings-manager).

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/kiarina/pydantic-settings-manager",
    "name": "pydantic-settings-manager",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": "pydantic, settings, configuration",
    "author": "kiarina",
    "author_email": "kiarinadawa@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/6b/1d/f89dfda7e15305fa1aceb5df236e344e4df287a1a1fd31516a5784e185db/pydantic_settings_manager-0.1.2.tar.gz",
    "platform": null,
    "description": "# pydantic-settings-manager\n\nA library for managing Pydantic settings objects.\n\n## Features\n\n- Two types of settings managers:\n  - `SingleSettingsManager`: For managing a single settings object\n  - `MappedSettingsManager`: For managing multiple settings objects mapped to keys\n- Support for loading settings from multiple sources\n- Command line argument overrides\n- Settings validation through Pydantic\n- Type hints and documentation\n\n## Installation\n\n```bash\npip install pydantic-settings-manager\n```\n\n## Quick Start\n\n### Single Settings Manager\n\n```python\nfrom pydantic_settings import BaseSettings\nfrom pydantic_settings_manager import SingleSettingsManager\n\nclass MySettings(BaseSettings):\n    name: str = \"default\"\n    value: int = 0\n\n# Create a settings manager\nmanager = SingleSettingsManager(MySettings)\n\n# Update settings from a configuration file\nmanager.user_config = {\"name\": \"from_file\", \"value\": 42}\n\n# Update settings from command line arguments\nmanager.cli_args = {\"value\": 100}\n\n# Get the current settings (combines both sources)\nsettings = manager.settings\nassert settings.name == \"from_file\"  # from user_config\nassert settings.value == 100  # from cli_args (overrides user_config)\n```\n\n### Mapped Settings Manager\n\n```python\nfrom pydantic_settings import BaseSettings\nfrom pydantic_settings_manager import MappedSettingsManager\n\nclass MySettings(BaseSettings):\n    name: str = \"default\"\n    value: int = 0\n\n# Create a settings manager\nmanager = MappedSettingsManager(MySettings)\n\n# Set up multiple configurations\nmanager.user_config = {\n    \"map\": {\n        \"dev\": {\"name\": \"development\", \"value\": 42},\n        \"prod\": {\"name\": \"production\", \"value\": 100}\n    }\n}\n\n# Select which configuration to use\nmanager.set_cli_args(\"dev\")\n\n# Get the current settings\nsettings = manager.settings\nassert settings.name == \"development\"\nassert settings.value == 42\n\n# Switch to a different configuration\nmanager.set_cli_args(\"prod\")\nsettings = manager.settings\nassert settings.name == \"production\"\nassert settings.value == 100\n```\n\n## Documentation\n\nFor more detailed documentation, please see the [GitHub repository](https://github.com/kiarina/pydantic-settings-manager).\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A library for managing Pydantic settings objects",
    "version": "0.1.2",
    "project_urls": {
        "Documentation": "https://github.com/kiarina/pydantic-settings-manager",
        "Homepage": "https://github.com/kiarina/pydantic-settings-manager",
        "Repository": "https://github.com/kiarina/pydantic-settings-manager"
    },
    "split_keywords": [
        "pydantic",
        " settings",
        " configuration"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a779155ba4859a03280d9151d861a0a966181438b34f101a1b05df11c358a97f",
                "md5": "a9c7d79896549996eb4b533e45b58dc5",
                "sha256": "049088f4b42d6fa48641142ec412c4442b7eedfa1417af78d8b249b3787589b8"
            },
            "downloads": -1,
            "filename": "pydantic_settings_manager-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a9c7d79896549996eb4b533e45b58dc5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 8388,
            "upload_time": "2024-12-12T03:39:45",
            "upload_time_iso_8601": "2024-12-12T03:39:45.796574Z",
            "url": "https://files.pythonhosted.org/packages/a7/79/155ba4859a03280d9151d861a0a966181438b34f101a1b05df11c358a97f/pydantic_settings_manager-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6b1df89dfda7e15305fa1aceb5df236e344e4df287a1a1fd31516a5784e185db",
                "md5": "7e05e28fa09e560587cd17293d6031f8",
                "sha256": "08e57e58f72d4f76e7970fbd2ad7f7a3a14d6e8b9cadfb001fabd94d8013ab9b"
            },
            "downloads": -1,
            "filename": "pydantic_settings_manager-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "7e05e28fa09e560587cd17293d6031f8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 6102,
            "upload_time": "2024-12-12T03:39:48",
            "upload_time_iso_8601": "2024-12-12T03:39:48.102430Z",
            "url": "https://files.pythonhosted.org/packages/6b/1d/f89dfda7e15305fa1aceb5df236e344e4df287a1a1fd31516a5784e185db/pydantic_settings_manager-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-12 03:39:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kiarina",
    "github_project": "pydantic-settings-manager",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pydantic-settings-manager"
}
        
Elapsed time: 0.40643s