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
File details
Details for the file configmate_pydantic_validator-0.1.0.tar.gz
.
File metadata
- Download URL: configmate_pydantic_validator-0.1.0.tar.gz
- Upload date:
- Size: 1.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.0 Darwin/23.2.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c37b8d0a4216f354e11c058a8e0f4538e476270a9a43f0a77642fb07be30b821 |
|
MD5 | e1351a38c88a904b9b65c92b4ab85d95 |
|
BLAKE2b-256 | 3c34be8df016dddf73c0c62429981c8c57719978aa2a303b83130cf562eedaa5 |
File details
Details for the file configmate_pydantic_validator-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: configmate_pydantic_validator-0.1.0-py3-none-any.whl
- Upload date:
- Size: 2.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.12.0 Darwin/23.2.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4d64b23ccec404183511451b2795105ec410626b8029707b9ab0331c3e6f46e9 |
|
MD5 | 93c17aa02c3b79f59b8b0677bd263397 |
|
BLAKE2b-256 | 76ed2dbb95804795eccfb13906283054b66010cb285fc69a37e80f603996a62f |