Application configuration manager
Project description
Project Configuration Manager
Supports configuration from yaml files and env.
The order of configuration overload(from highest priority to lowest):
- Parameters set in environment variables;
- Files specified via the environment variable
{PROJECT_NAME}_CONFIG; - Files specified in the process startup parameter
--config(-c); - Files specified by the
config_pathsparameter in the initialization of theConfigManagerclass.
Manager Parameters:
config_cls(pydantic.BaseModel) - class, used for validating and typing config fields;project_metadata(dict) - Basic information about the project (name, version).nameis used to generate environment variables;config_paths(List[str]) - Paths to the application configuration files;project_metadata_as: (Optional[str]) - This key will be assigned toproject_metadatain the configuration object. By defaultproject. IfNoneis set,project_metadatawill not be added to the config;root_config_dir(Optional[str]) - Base path to the directory with configuration files to set relative paths;pre_validation_hook(Callable[[dict], dict]) - The method called after loading the configuration before validation. If it is necessary to perform any transformations (downloading key files from the file system, etc.);parse_config_paths_from_args(bool) - Specifies whether it is necessary to automatically search for configuration files in the command line options or not;parse_config_paths_from_env(bool) - Specifies whether it is necessary to automatically search for configuration files in an environment variable({PROJECT_NAME}_CONFIG) or not;multiprocessing_mode(bool) - Specifies whether it is necessary to usemultiprocessing.Manager().dict()to store the configuration.
Manager Methods:
load_config- Loads the configuration from configuration files and environment variables. It can be called repeatedly to update the configuration object. Returns the proxy configuration object;get_config- Returns a new proxy object to the configuration without loading the configuration;get_multiprocessing_config_dict- Returnsmultiprocessing.Manager().dict()for passing to child processes. This option is available only withmultiprocessing_mode=True;set_multiprocessing_config_dict- Acceptsmultiprocessing.Manager().dict(). Sets as the configuration source. It must be installed in child processes during initialization. Available only withmultiprocessing_mode=True.
Creation of environment variable names:
A transformation is used for each element of the name:
import re
re.sub(pattern='[^a-zA-Z0-9]', repl='_', flags=re.DOTALL, string=name.upper())
For example, the project name Test project is converted to TEST_PROJECT.
The variable name is formed from {PROJECT_NAME}_ + '_'.join(path_to_variable).
from pydantic import BaseModel
from qstd_config import BaseConfig, ConfigManager
class Config(BaseConfig):
class Example(BaseModel):
class Child(BaseModel):
value: str
child: Child
value: int
example: Example
manager = ConfigManager(Config, {'name': 'Test project', 'version': 'version'})
Generates the following environment variables:
TEST_PROJECT_EXAMPLE_VALUE;TEST_PROJECT_EXAMPLE_CHILD_VALUE.
Basic example
from pydantic import BaseModel
from qstd_config import ConfigManager, BaseConfig
class Config(BaseConfig):
class Example(BaseModel):
example: str
example: Example
manager = ConfigManager(
Config,
{'name': 'Project name', 'version': 'project version'}
)
config = manager.load_config()
Basic multiprocessing example
from multiprocessing import get_context
from pydantic import BaseModel
from qstd_config import ConfigManager, BaseConfig
class Config(BaseConfig):
class Example(BaseModel):
example: str
example: Example
manager = ConfigManager(
Config,
{'name': 'Project name', 'version': 'project version'},
multiprocessing_mode=True
)
config = manager.load_config()
def run_child_process(config_dict):
manager.set_multiprocessing_config_dict(config_dict)
...
get_context('spawn').Process(
target=run_child_process,
daemon=True,
args=(manager.get_multiprocessing_config_dict(),)
).start()
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qstd_config-0.3.2.tar.gz.
File metadata
- Download URL: qstd_config-0.3.2.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a1ab08cb8a1e7fe98fff645e7aeaebf0c1807dd367c37fd4a8c71633e1178e7
|
|
| MD5 |
7bd4b7dec679e0a320e647648f8f9c9a
|
|
| BLAKE2b-256 |
71827566f0b3071aac7579e066df0649c3f2c3ca3ca146a85599e10997798297
|
File details
Details for the file qstd_config-0.3.2-py3-none-any.whl.
File metadata
- Download URL: qstd_config-0.3.2-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f6f4e365bc9947f0dc2928cae859948a3e87bff853db92cf3efe37e96a2a282
|
|
| MD5 |
4abdbd2c562ecbe33102c5a0aa0f3953
|
|
| BLAKE2b-256 |
66c7cad03a84d50118ab636fa534e34d3a427ae2244140a8a822c0b51a6b33cf
|