pyappconf package
Strongly typed and validated configuration supporting multiple file types, dynamic instantiation, and environment variables
pyappconf.constants module
pyappconf.model module
-
class pyappconf.model.AppConfig(app_name, config_name='config', custom_config_folder=None, default_format=ConfigFormats.TOML, multi_format=False, schema_url=None, toml_encoder=<class 'pyappconf.encoding.ext_toml.CustomTomlEncoder'>, yaml_encoder=<class 'pyappconf.encoding.ext_yaml.CustomDumper'>, json_encoder=<class 'pyappconf.encoding.ext_json.ExtendedJSONEncoder'>, py_config_encoder=<function pydantic_model_to_python_config_file>, py_config_stub_encoder=<function pydantic_model_to_python_config_stub_file>, py_config_imports=None, py_config_create_stub=True, py_config_generate_model_class_in_stub=False, pyproject_encoder=<function add_model_to_pyproject_toml>)[source]
Bases: object
-
__init__(app_name, config_name='config', custom_config_folder=None, default_format=ConfigFormats.TOML, multi_format=False, schema_url=None, toml_encoder=<class 'pyappconf.encoding.ext_toml.CustomTomlEncoder'>, yaml_encoder=<class 'pyappconf.encoding.ext_yaml.CustomDumper'>, json_encoder=<class 'pyappconf.encoding.ext_json.ExtendedJSONEncoder'>, py_config_encoder=<function pydantic_model_to_python_config_file>, py_config_stub_encoder=<function pydantic_model_to_python_config_stub_file>, py_config_imports=None, py_config_create_stub=True, py_config_generate_model_class_in_stub=False, pyproject_encoder=<function add_model_to_pyproject_toml>)[source]
-
property config_base_location: Path
- Return type:
Path
-
property config_file_name: str
- Return type:
str
-
property config_folder: Path
- Return type:
Path
-
property config_location: Path
- Return type:
Path
-
copy(**kwargs)[source]
- Return type:
AppConfig
-
dict(exclude=None)[source]
- Return type:
Dict
[str
, Any
]
-
property supported_formats: List[ConfigFormats]
- Return type:
List
[ConfigFormats
]
-
class pyappconf.model.BaseConfig(_env_file='<object object>', _env_file_encoding=None, _env_nested_delimiter=None, _secrets_dir=None, **values)[source]
Bases: BaseSettings
-
classmethod get_deserializer(config_format=None)[source]
- Return type:
Callable
[[Union
[str
, Path
], Optional
[Dict
[str
, Any
]]], BaseConfig
]
-
get_serializer()[source]
- Return type:
Callable
[[Union
[str
, Path
, None
], Optional
[Dict
[str
, Any
]]], str
]
-
classmethod load(path=None, multi_format=None, model_kwargs=None)[source]
- Return type:
BaseConfig
-
classmethod load_or_create(path=None, multi_format=None, model_kwargs=None)[source]
- Return type:
BaseConfig
-
classmethod load_recursive(path=None, multi_format=None, model_kwargs=None)[source]
Searches the passed path or current directory for a config with the correct name,
and if not found goes the parent directory and repeats the search.
If the config is not found after reaching the root directory,
it will look at the location in the config.
- Parameters:
path (Union
[str
, Path
, None
]) – The path to start searching from, defaults to the current directory
- Return type:
BaseConfig
- Returns:
-
-
classmethod parse_json(in_path, model_kwargs=None)[source]
- Return type:
BaseConfig
-
classmethod parse_py_config(in_path, model_kwargs=None)[source]
- Return type:
BaseConfig
-
classmethod parse_pyproject_toml(in_path, model_kwargs=None)[source]
- Return type:
BaseConfig
-
classmethod parse_toml(in_path, model_kwargs=None)[source]
- Return type:
BaseConfig
-
classmethod parse_yaml(in_path, model_kwargs=None)[source]
- Return type:
BaseConfig
-
save(serializer_kwargs=None, **kwargs)[source]
-
classmethod schema(by_alias=True, ref_template='#/definitions/{model}')[source]
- Return type:
Dict
[str
, Any
]
-
classmethod set_settings_from_class_if_none(v)[source]
-
settings: AppConfig
-
to_json(out_path=None, json_kwargs=None, include_schema_url=True, **kwargs)[source]
- Return type:
str
-
to_py_config(out_path=None, py_config_kwargs=None, include_stub_file=None, generate_model_class_in_stub_file=None)[source]
- Return type:
str
-
to_py_config_stub(out_path=None, py_config_stub_kwargs=None)[source]
- Return type:
str
-
to_pyproject_toml(out_path=None, pyproject_toml_kwargs=None, **kwargs)[source]
- Return type:
str
-
to_toml(out_path=None, toml_kwargs=None, **kwargs)[source]
- Return type:
str
-
to_yaml(out_path=None, yaml_kwargs=None, include_schema_url=True, **kwargs)[source]
- Return type:
str
-
class pyappconf.model.ConfigFormats(value)[source]
Bases: str
, Enum
An enumeration.
-
JSON = 'json'
-
PY = 'py'
-
PYPROJECT = 'pyproject.toml'
-
TOML = 'toml'
-
YAML = 'yaml'
-
classmethod from_path(path)[source]
- Return type:
ConfigFormats
pyappconf.pyproject module
-
pyappconf.pyproject.add_model_to_pyproject_toml(config_data, path, config_name, toml_encoder)[source]
- Return type:
str
-
pyappconf.pyproject.read_config_data_from_pyproject_toml(path, config_name)[source]
- Return type:
dict