Extends configmate with pydantic validation logic.
Project description
configmate-pydantic-validator
Extends configmate
to levarage Pydantic for config validation.
Installation
pip install configmate-pydanticvalidator
OR directly with the extras of configmate
:
pip install configmate[pydantic]
Usage
By loading this plugin, configmate
will use Pydantic to validate the config.
Under the hood, a new validator is registered to configmate.components.validators.TypeValidatorFactory
.
This validator will be used for any non-function passed to validation
in configmate.get_config.
from typing import Dict
import dataclasses
import configmate
@dataclasses.dataclass
class Config:
host: str
port: int
config = configmate.get_config(
"config.json", # main config
validation=Dict[str, str], # pydantic will handle validation
)
## >> {'host': 'localhost', 'port': '8080'} # note that port is a string due to pydantic
config = configmate.get_config(
"config.json", # main config
validation=Config, # pydantic will handle validation
)
## >> Config(host='localhost', port=8080) # port is an int as expected
config = configmate.get_config(
"config.json", # main config
validation=lambda config_dict: ..., # callables will be called with the config dict (as without this plugin)
)
## >> ... # whatever the callable returns
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for configmate_pydantic_validator-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8048762455322b62af83df98a0db8bedf3d4cfe48a4064dcbc67e66a2c81752c |
|
MD5 | d370143468bdcd8190d28c570cdb826b |
|
BLAKE2b-256 | b9e31429ef89034ca011ce9af152cbb01690609b941f2c829df8d51c4a3f8289 |
Close
Hashes for configmate_pydantic_validator-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 48d1c0136b9bf53ef667064154830812cf73512c831144b8f5d5c8be6a45865d |
|
MD5 | 74dc40f68cf76424f7ca32c86f6e18ab |
|
BLAKE2b-256 | f0d8fb9b34812ae3615f1d8312316c3aa73783c5514245ed57c05f75cdb6e74c |