Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rupurt/pydanticutils
Pydantic utility helpers
https://github.com/rupurt/pydanticutils
pydantic python
Last synced: 4 months ago
JSON representation
Pydantic utility helpers
- Host: GitHub
- URL: https://github.com/rupurt/pydanticutils
- Owner: rupurt
- License: mit
- Created: 2024-04-23T20:58:41.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-08-01T02:19:51.000Z (7 months ago)
- Last Synced: 2024-10-10T14:38:56.192Z (4 months ago)
- Topics: pydantic, python
- Language: Python
- Homepage:
- Size: 114 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pydanticutils
[](https://github.com/rupurt/pydanticutils/actions/workflows/ci.yaml)

[Pydantic](https://docs.pydantic.dev/latest/) 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_yamlsettings = 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
``````console
> make setup
``````console
> make test
```## Publish Package to PyPi
```console
> make pypi
```## License
`pydanticutils` is released under the [MIT license](./LICENSE)