Skip to main content

pydantic loader module

Project description

Code style: black

PyConfig

Configuration management using pydantic and a bit of sugar.

This library provides a loadconfig and saveconfig method to easily load and save python app configurations.

# config.py file

from pydantic import BaseSettings


class DummyConfig(BaseSettings):
    """An app configuration class"""

    a: int = 1
    b: str = "ABC"


# The parameter to which the above instance will be assigned to.
CONFIG: DummyConfig
Load a default config

>>> import config
>>> from pyconfig.config import load_config
>>> config.CONFIG = load_config(config.DummyConfig)
>>> config.CONFIG

DummyConfig(a=1, b='ABC')
>>> import config
>>> from pyconfig.config import load_config
>>> from pathlib import Path

>>> config_file = Path("A_CONFIG_FILE.json")
>>> config.CONFIG = load_config(config.DummyConfig,config_file)

Load failed. Config file A_CONFIG_FILE.json does not exist. LOADING DEFAULTS 

>>> config.CONFIG

DummyConfig(a=1, b='ABC')

>>> config.CONFIG=load_config(config.DummyConfig,config_file,on_error_return_default=False)

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\sander\Dropbox\data\aptana\pyconfig\pyconfig\config.py", line 55, in load_config
    conf_data = _load_json(config_file)
  File "C:\Users\sander\Dropbox\data\aptana\pyconfig\pyconfig\config.py", line 21, in _load_json
    raise CfgError(f"Load failed. Config file {config_file} does not exist.")
pyconfig.config.CfgError: Load failed. Config file A_CONFIG_FILE.json does not exist.

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

pydantic_loader-0.2.1.tar.gz (5.3 kB view hashes)

Uploaded Source

Built Distribution

pydantic_loader-0.2.1-py3-none-any.whl (3.7 kB view hashes)

Uploaded Python 3

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