Metadata-Version: 2.1
Name: pydanticutils
Version: 0.0.3
Summary: Pydantic utility helpers
Author-email: Alex Kwiatkowski <alex+pypi@fremantle.io>
Project-URL: Homepage, https://github.com/rupurt/pydanticutils
Project-URL: Issues, https://github.com/rupurt/pydanticutils/issues
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pydantic >=2.5.0
Requires-Dist: pydantic-settings >=2.2.1
Requires-Dist: PyYAML ~=6.0.1
Provides-Extra: test
Requires-Dist: build >=1.2.1 ; extra == 'test'
Requires-Dist: twine >=5.0.0 ; extra == 'test'
Requires-Dist: ruff >=0.3.4 ; extra == 'test'
Requires-Dist: pip-tools >=7.4.1 ; extra == 'test'
Requires-Dist: pygments >=2.17.0 ; extra == 'test'
Requires-Dist: pyhamcrest >=2.1.0 ; extra == 'test'
Requires-Dist: pyright >=1.1.0 ; extra == 'test'
Requires-Dist: pytest >=8.1.0 ; extra == 'test'
Requires-Dist: pytest-cov >=5.0.0 ; extra == 'test'
Requires-Dist: pytest-recording >=0.13.1 ; extra == 'test'
Requires-Dist: pytest-unordered >=0.6.0 ; extra == 'test'
Requires-Dist: pytest-watcher >=0.4.0 ; extra == 'test'

# pydanticutils
[![ci status](https://github.com/rupurt/pydanticutils/actions/workflows/ci.yaml/badge.svg?branch=main)](https://github.com/rupurt/pydanticutils/actions/workflows/ci.yaml)
![pypi](https://img.shields.io/pypi/v/pydanticutils.svg)
![versions](https://img.shields.io/pypi/pyversions/pydanticutils.svg)

Pydantic utility helpers

## Usage

1. Install the package from pypi

```console
> pip install pydanticutils
```

2. Create a pydantic settings class

```python
class DatabaseSettings(BaseModel):
    host: str = Field(default="0.0.0.0")
    port: int = Field(default=5432)


class AppSettings(BaseSettings):
    model_config = SettingsConfigDict(env_prefix="APP_", env_nested_delimiter="__")

    log_level: str = Field(default="INFO")
    database: DatabaseSettings = Field(default_factory=DatabaseSettings)
```

3. Read a configuration file into the settings class

```python
from pydanticutils import read_yaml

settings = read_yaml("/path/to/config.yaml", AppSettings)
```

## Development

This repository manages the dev environment as a Nix flake and requires [Nix to be installed](https://github.com/DeterminateSystems/nix-installer)

```console
> nix develop -c $SHELL
```

```shell
> make setup
```

```shell
> make test
```

## Publish Package to PyPi

```shell
> make distribution
```

## License

`pydanticutils` is released under the [MIT license](./LICENSE)
