pydantic loader module.
Project description
PyConfig
Configuration management using pydantic and a bit of sugar.
This library provides a load and save method for pydantic config settings.
Settings can be saved in .json
and .toml
format. The latter is experimental.
"""Small example"""
from pydantic_loader import load_config
from pydantic_loader.config_obj import PydanticConfig
class DummyConfig(PydanticConfig):
"""An app configuration class
Define this class according to pydantic BaseSettings.
"""
a: int = 1
b: str = "ABC"
# Load a json file with config data and include it in the DummyConfig.
config = DummyConfig.load_config("a json config file.json")
# Providing a non existing file will raise a CfgError
# It will return a default instance of the config class when on_error_return_default=True
config = DummyConfig.load_config("invalid_file.json", on_error_return_default=True)
# Using the load_config allows for loading pydantic `BaseSettings` class
config = load_config(DummyConfig,"Json or Toml config file.")
# SAVE A CONFIG
from pydantic_loader import save_config
# Your config file should have the extension .toml, .tml or .json to determine how to encode
# the pydantic instance.
save_config(config,"a json or toml config file")
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
pydantic_loader-0.8.0.tar.gz
(9.6 kB
view hashes)
Built Distribution
Close
Hashes for pydantic_loader-0.8.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd04c29bc9a748f4d991f296d133dfaba424521b025366b650cf8095fc4db970 |
|
MD5 | e751f4dfc8211cf9e359662a87aa53f2 |
|
BLAKE2b-256 | b6bdaf6938603d47237f2c11f11853be3d51f9e0573ed3f8be4c9149a9207336 |