Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

configmate_pydantic_validator-0.1.0.tar.gz (1.9 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file configmate_pydantic_validator-0.1.0.tar.gz.

File metadata

File hashes

Hashes for configmate_pydantic_validator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c37b8d0a4216f354e11c058a8e0f4538e476270a9a43f0a77642fb07be30b821
MD5 e1351a38c88a904b9b65c92b4ab85d95
BLAKE2b-256 3c34be8df016dddf73c0c62429981c8c57719978aa2a303b83130cf562eedaa5

See more details on using hashes here.

File details

Details for the file configmate_pydantic_validator-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for configmate_pydantic_validator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4d64b23ccec404183511451b2795105ec410626b8029707b9ab0331c3e6f46e9
MD5 93c17aa02c3b79f59b8b0677bd263397
BLAKE2b-256 76ed2dbb95804795eccfb13906283054b66010cb285fc69a37e80f603996a62f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page