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.1.0a0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2f5bb147fc84fd825457107c5a9652589961ff18e6ee0631244f00672cb95b6 |
|
MD5 | 13eb9b34ebf7b7fa7567fd9aa88f3b37 |
|
BLAKE2b-256 | f180d16f7cf79fccb33b5e9390dba0207662ef3ac089501d35d33f74ada13c1e |
Close
Hashes for configmate_pydantic_validator-0.1.0a0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c43724abc8a6c14af7337fbfcec2fd0b0de2b220a993c47bc47c0b3e2445650a |
|
MD5 | dfa233c150633a84a80c3d276637709f |
|
BLAKE2b-256 | d63d4ea16a51bd51f06c89f1341a8a73347e8c6c215b0953798d61b4033f1d8d |