# 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_paths` parameter in the initialization of the `ConfigManager` class.
---
Manager Parameters:
- `config_cls`(`pydantic.BaseModel`) - class, used for validating and typing config fields;
- `project_metadata`(`dict`) - Basic information about the project (name, version).
`name` is 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 to `project_metadata` in the configuration object.
By default `project`. If `None` is set, `project_metadata` will 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 use `multiprocessing.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` - Returns `multiprocessing.Manager().dict()` for passing to child processes.
This option is available only with `multiprocessing_mode=True`;
- `set_multiprocessing_config_dict` - Accepts `multiprocessing.Manager().dict()`. Sets as the configuration source.
It must be installed in child processes during initialization. Available only with `multiprocessing_mode=True`.
---
Creation of environment variable names:
A transformation is used for each element of the name:
```python
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)`.
```python
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
```python
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
```python
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()
```
Raw data
{
"_id": null,
"home_page": "https://github.com/QuisEgoSum/qstd-config",
"name": "qstd-config",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "config yaml env",
"author": "QuisEgoSum",
"author_email": "subbotin.evdokim@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ed/1b/fcd830bdf516e4b3779ad4116f2377649db8167398c38b347288507d6b33/qstd_config-0.3.1.tar.gz",
"platform": null,
"description": "\n# Project Configuration Manager\n\nSupports configuration from yaml files and env.\n\nThe order of configuration overload(from highest priority to lowest):\n- Parameters set in environment variables;\n- Files specified via the environment variable `{PROJECT_NAME}_CONFIG`;\n- Files specified in the process startup parameter `--config`(`-c`);\n- Files specified by the `config_paths` parameter in the initialization of the `ConfigManager` class.\n\n---\n\nManager Parameters:\n- `config_cls`(`pydantic.BaseModel`) - class, used for validating and typing config fields;\n- `project_metadata`(`dict`) - Basic information about the project (name, version).\n`name` is used to generate environment variables;\n- `config_paths`(`List[str]`) - Paths to the application configuration files;\n- `project_metadata_as`: (`Optional[str]`) - This key will be assigned to `project_metadata` in the configuration object.\nBy default `project`. If `None` is set, `project_metadata` will not be added to the config;\n- `root_config_dir`(`Optional[str]`) - Base path to the directory with configuration files to set relative paths;\n- `pre_validation_hook`(`Callable[[dict], dict]`) - The method called after loading the configuration before validation.\nIf it is necessary to perform any transformations (downloading key files from the file system, etc.);\n- `parse_config_paths_from_args`(`bool`) - Specifies whether it is necessary to automatically search for configuration\nfiles in the command line options or not;\n- `parse_config_paths_from_env`(`bool`) - Specifies whether it is necessary to automatically search for configuration\nfiles in an environment variable(`{PROJECT_NAME}_CONFIG`) or not;\n- `multiprocessing_mode`(`bool`) - Specifies whether it is necessary to use `multiprocessing.Manager().dict()` to store\nthe configuration.\n\n\n---\n\nManager Methods:\n- `load_config` - Loads the configuration from configuration files and environment variables.\nIt can be called repeatedly to update the configuration object. Returns the proxy configuration object;\n- `get_config` - Returns a new proxy object to the configuration without loading the configuration;\n- `get_multiprocessing_config_dict` - Returns `multiprocessing.Manager().dict()` for passing to child processes.\nThis option is available only with `multiprocessing_mode=True`;\n- `set_multiprocessing_config_dict` - Accepts `multiprocessing.Manager().dict()`. Sets as the configuration source.\nIt must be installed in child processes during initialization. Available only with `multiprocessing_mode=True`.\n\n---\n\nCreation of environment variable names:\n\n\nA transformation is used for each element of the name:\n```python\nimport re\nre.sub(pattern='[^a-zA-Z0-9]', repl='_', flags=re.DOTALL, string=name.upper())\n```\n\nFor example, the project name `Test project` is converted to `TEST_PROJECT`.\n\nThe variable name is formed from `{PROJECT_NAME}_` + `'_'.join(path_to_variable)`.\n\n```python\nfrom pydantic import BaseModel\nfrom qstd_config import BaseConfig, ConfigManager\n\nclass Config(BaseConfig):\n class Example(BaseModel):\n class Child(BaseModel):\n value: str\n \n child: Child\n value: int\n \n example: Example\n\nmanager = ConfigManager(Config, {'name': 'Test project', 'version': 'version'})\n```\n\nGenerates the following environment variables:\n- `TEST_PROJECT_EXAMPLE_VALUE`;\n- `TEST_PROJECT_EXAMPLE_CHILD_VALUE`.\n\n---\n\nBasic example\n\n```python\nfrom pydantic import BaseModel\n\nfrom qstd_config import ConfigManager, BaseConfig\n\nclass Config(BaseConfig):\n class Example(BaseModel):\n example: str\n \n example: Example\n \n \nmanager = ConfigManager(\n Config,\n {'name': 'Project name', 'version': 'project version'}\n)\n\nconfig = manager.load_config()\n```\n\n---\n\nBasic multiprocessing example\n\n```python\nfrom multiprocessing import get_context\nfrom pydantic import BaseModel\n\nfrom qstd_config import ConfigManager, BaseConfig\n\nclass Config(BaseConfig):\n class Example(BaseModel):\n example: str\n \n example: Example\n \n \nmanager = ConfigManager(\n Config,\n {'name': 'Project name', 'version': 'project version'},\n multiprocessing_mode=True\n)\n\nconfig = manager.load_config()\n\ndef run_child_process(config_dict):\n manager.set_multiprocessing_config_dict(config_dict)\n ...\n\n\nget_context('spawn').Process(\n target=run_child_process,\n daemon=True,\n args=(manager.get_multiprocessing_config_dict(),)\n).start()\n```\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Application configuration manager",
"version": "0.3.1",
"project_urls": {
"Homepage": "https://github.com/QuisEgoSum/qstd-config"
},
"split_keywords": [
"config",
"yaml",
"env"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "66b0cb68b12ba79ab521f5fc64c4216b44c45d8e874a70a48377f043f13b8ab1",
"md5": "62cf79de79a1f11c832cf0e1ad099239",
"sha256": "35643950e91f531798313182af747b2e3c825a9c425adf01114ff066486941de"
},
"downloads": -1,
"filename": "qstd_config-0.3.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "62cf79de79a1f11c832cf0e1ad099239",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 7602,
"upload_time": "2024-09-02T19:50:26",
"upload_time_iso_8601": "2024-09-02T19:50:26.971923Z",
"url": "https://files.pythonhosted.org/packages/66/b0/cb68b12ba79ab521f5fc64c4216b44c45d8e874a70a48377f043f13b8ab1/qstd_config-0.3.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ed1bfcd830bdf516e4b3779ad4116f2377649db8167398c38b347288507d6b33",
"md5": "56b9a0abd89c1eade6b6afe90f70b712",
"sha256": "3978c4732edb7f8db351cad06672db08f28146ad45c24f0cad6ff3211e2a9018"
},
"downloads": -1,
"filename": "qstd_config-0.3.1.tar.gz",
"has_sig": false,
"md5_digest": "56b9a0abd89c1eade6b6afe90f70b712",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 7349,
"upload_time": "2024-09-02T19:50:29",
"upload_time_iso_8601": "2024-09-02T19:50:29.830422Z",
"url": "https://files.pythonhosted.org/packages/ed/1b/fcd830bdf516e4b3779ad4116f2377649db8167398c38b347288507d6b33/qstd_config-0.3.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-02 19:50:29",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "QuisEgoSum",
"github_project": "qstd-config",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "qstd-config"
}