qstd-config


Nameqstd-config JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/QuisEgoSum/qstd-config
SummaryApplication configuration manager
upload_time2024-04-07 17:43:38
maintainerNone
docs_urlNone
authorQuisEgoSum
requires_python>=3.7
licenseMIT
keywords config yaml env
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# 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'}
)

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/88/90/836a6e748780e9bd7772e260437d1c2aafcc64721cf168faa3f9973fe548/qstd_config-0.1.0.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)\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.1.0",
    "project_urls": {
        "Homepage": "https://github.com/QuisEgoSum/qstd-config"
    },
    "split_keywords": [
        "config",
        "yaml",
        "env"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "37b3002621c6090820fba3dfdadc4a67c8d6677ae8a6e96767064a0f29d7808e",
                "md5": "9929b6c61e87dbdcc4c834554c09475d",
                "sha256": "fee98be78a00150354d502d3d62dc218791c4d59531d9df02f8455b67ee3588a"
            },
            "downloads": -1,
            "filename": "qstd_config-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9929b6c61e87dbdcc4c834554c09475d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7499,
            "upload_time": "2024-04-07T17:43:36",
            "upload_time_iso_8601": "2024-04-07T17:43:36.704549Z",
            "url": "https://files.pythonhosted.org/packages/37/b3/002621c6090820fba3dfdadc4a67c8d6677ae8a6e96767064a0f29d7808e/qstd_config-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8890836a6e748780e9bd7772e260437d1c2aafcc64721cf168faa3f9973fe548",
                "md5": "8c2de13737b624a266c402d926d102c4",
                "sha256": "52d3055f0e4e0c750605c2b7e937d8547f6b77ab3f7adcce2930d5d834040ae3"
            },
            "downloads": -1,
            "filename": "qstd_config-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8c2de13737b624a266c402d926d102c4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 7184,
            "upload_time": "2024-04-07T17:43:38",
            "upload_time_iso_8601": "2024-04-07T17:43:38.719468Z",
            "url": "https://files.pythonhosted.org/packages/88/90/836a6e748780e9bd7772e260437d1c2aafcc64721cf168faa3f9973fe548/qstd_config-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-07 17:43:38",
    "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"
}
        
Elapsed time: 0.22880s