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.

Files for pydantic_loader, version 0.2.1
Filename, size File type Python version Upload date Hashes
Filename, size pydantic_loader-0.2.1-py3-none-any.whl (3.7 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size pydantic_loader-0.2.1.tar.gz (5.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page