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
Metadata
Release files for configmate-pydantic-validator 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| configmate_pydantic_validator-0.1.0.tar.gz | 1.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| configmate_pydantic_validator-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 4.6 kB
Release files / configmate_pydantic_validator-0.1.0.tar.gz
| Download URL | configmate_pydantic_validator-0.1.0.tar.gz |
|---|---|
| Size | 1.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c37b8d0a4216f354e11c058a8e0f4538e476270a9a43f0a77642fb07be30b821
|
|
BLAKE2b-256 checksum How to use checksums |
3c34be8df016dddf73c0c62429981c8c57719978aa2a303b83130cf562eedaa5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.12.0 Darwin/23.2.0
|
Release files / configmate_pydantic_validator-0.1.0-py3-none-any.whl
| Download URL | configmate_pydantic_validator-0.1.0-py3-none-any.whl |
|---|---|
| Size | 2.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4d64b23ccec404183511451b2795105ec410626b8029707b9ab0331c3e6f46e9
|
|
BLAKE2b-256 checksum How to use checksums |
76ed2dbb95804795eccfb13906283054b66010cb285fc69a37e80f603996a62f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.12.0 Darwin/23.2.0
|