<a name="top"></a>
<a name="overview"></a>
# Overview
This is a module for reading configuration files.
Currently, the module only supports YAML-formatted files.
Features:
- Retrieve deeply nested values using dot notation, e.g. `section1.key1`
- Retrieve values using wildcards, e.g. `section1.*.key2`
- Configuration files can be templated (Jinja)
# Prerequisites:
- Python 3.4+
# Installation
* From pypi: `pip3 install bertdotconfig`
* From this git repo: `pip3 install git+https://github.com/berttejeda/bert.config.git`<br />
Note: To install a specific version of the library from this git repo, <br />
suffix the git URL in the above command with @{ tag name }, e.g.: <br />
git+https://github.com/berttejeda/bert.config.git@3.0.0
# Usage Examples
## Load a configuration file and retrieve specified key value
Given:
- Config file at `/home/myuser/myconfig.yaml`
- with contents:<br />
```yaml
section1:
key1: value1
key2: value2
key3: value3
```
```python
from bertdotconfig import Config
# Initialize App Config
config = Config(config_file_uri='~/myconfig.yaml').read()
value = config.get('section1.key')
print(value)
```
The above should return `value1`
## Load a configuration file and retrieve a deeply nested value
Given:
- Config file at `/home/myuser/myconfig.yaml`
- with contents:<br />
```yaml
section1:
subsection1:
item1:
subitem1: value1
item2: value2
item3: value3
subsection2:
item1: value1
item2: value2
item3: value3
key1: value1
key2: value2
key3: value3
section2:
item1: value1
```
```python
from bertdotconfig import Config
# Initialize App Config
config = Config(config_file_uri='~/myconfig.yaml').read()
value = config.get('section1.subsection1.item2')
print(value)
```
The above should return `value2`
## Load a configuration file and retrieve specified key value using wildcard notation
Given:
- Config file at `/home/myuser/myconfig.yaml`
- with contents:<br />
```yaml
section1:
subsection1:
item1:
subitem1: value1
item2: value2
item3: value3
subsection2:
item1: value1
item2: value2
item3: value3
key1: value1
key2: value2
key3: value3
section2:
item1: value1
```
```python
from bertdotconfig import Config
# Initialize App Config
config = Config(config_file_uri='~/myconfig.yaml').read()
value = config.get('section1.*.item1')
print(value)
```
The above should return `[{'subitem1': 'value1'}, 'value1']`
Note: When retrieving values via wildcard, the return value is a list object.
## Load a configuration file as a python object
Same as the above examples, just invoke the Config object
with `as_object=True`, as with
`config = Config('~/myconfig.yaml', as_object=True).read()`
In this case, retrieving values from the object can be done via dot-notation,
as with: `print(config.section1.subsection1.item2)`, or via `get` method, as with
`print(settings.section1.subsection1.item2)`
Note: This approach does not support retrieving values via wildcard reference.
Raw data
{
"_id": null,
"home_page": "https://github.com/berttejeda/bert.config",
"name": "bertdotconfig",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.4",
"maintainer_email": "",
"keywords": "yaml,configuration,config,file,python,settings",
"author": "Engelbert Tejeda",
"author_email": "berttejeda@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/a2/13/603a9ed6152a04e17d3356369cc7e173472718adbf4f391ad4b5a6014a47/bertdotconfig-4.4.0.tar.gz",
"platform": null,
"description": "<a name=\"top\"></a>\n<a name=\"overview\"></a>\n\n# Overview\n\nThis is a module for reading configuration files.\n\nCurrently, the module only supports YAML-formatted files.\n\nFeatures:\n- Retrieve deeply nested values using dot notation, e.g. `section1.key1`\n- Retrieve values using wildcards, e.g. `section1.*.key2`\n- Configuration files can be templated (Jinja)\n\n# Prerequisites:\n\n- Python 3.4+\n\n# Installation\n\n* From pypi: `pip3 install bertdotconfig`\n* From this git repo: `pip3 install git+https://github.com/berttejeda/bert.config.git`<br />\n Note: To install a specific version of the library from this git repo, <br />\n suffix the git URL in the above command with @{ tag name }, e.g.: <br />\n git+https://github.com/berttejeda/bert.config.git@3.0.0\n\n# Usage Examples\n\n## Load a configuration file and retrieve specified key value\n\nGiven:\n- Config file at `/home/myuser/myconfig.yaml`\n- with contents:<br />\n```yaml\nsection1:\n key1: value1\n key2: value2\n key3: value3\n```\n\n```python\nfrom bertdotconfig import Config\n# Initialize App Config\nconfig = Config(config_file_uri='~/myconfig.yaml').read()\nvalue = config.get('section1.key')\nprint(value)\n```\n\nThe above should return `value1`\n\n## Load a configuration file and retrieve a deeply nested value\n\nGiven:\n- Config file at `/home/myuser/myconfig.yaml`\n- with contents:<br />\n```yaml\nsection1:\n subsection1:\n item1:\n subitem1: value1\n item2: value2\n item3: value3\n subsection2:\n item1: value1\n item2: value2\n item3: value3\n key1: value1\n key2: value2\n key3: value3\nsection2:\n item1: value1\n```\n\n```python\nfrom bertdotconfig import Config\n# Initialize App Config\nconfig = Config(config_file_uri='~/myconfig.yaml').read()\nvalue = config.get('section1.subsection1.item2')\nprint(value)\n```\n\nThe above should return `value2`\n\n## Load a configuration file and retrieve specified key value using wildcard notation\n\nGiven:\n- Config file at `/home/myuser/myconfig.yaml`\n- with contents:<br />\n```yaml\nsection1:\n subsection1:\n item1:\n subitem1: value1\n item2: value2\n item3: value3\n subsection2:\n item1: value1\n item2: value2\n item3: value3\n key1: value1\n key2: value2\n key3: value3\nsection2:\n item1: value1\n```\n\n```python\nfrom bertdotconfig import Config\n# Initialize App Config\nconfig = Config(config_file_uri='~/myconfig.yaml').read()\nvalue = config.get('section1.*.item1')\nprint(value)\n```\n\nThe above should return `[{'subitem1': 'value1'}, 'value1']`\n\nNote: When retrieving values via wildcard, the return value is a list object.\n\n## Load a configuration file as a python object\n\nSame as the above examples, just invoke the Config object\nwith `as_object=True`, as with \n`config = Config('~/myconfig.yaml', as_object=True).read()`\n\nIn this case, retrieving values from the object can be done via dot-notation, \nas with: `print(config.section1.subsection1.item2)`, or via `get` method, as with\n`print(settings.section1.subsection1.item2)`\n\nNote: This approach does not support retrieving values via wildcard reference.\n",
"bugtrack_url": null,
"license": "",
"summary": "Module for reading configuration files",
"version": "4.4.0",
"split_keywords": [
"yaml",
"configuration",
"config",
"file",
"python",
"settings"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "158f40917dc40e82ecdee0009452b8fcb27e126cbfde975519e6f3086483af7f",
"md5": "9aacd7d93806b3f66b3ddc42ac0659cf",
"sha256": "58f280529b21d89cd9d909db503e9dad52cd3a03ecbc5bcf35d2fa10a811686c"
},
"downloads": -1,
"filename": "bertdotconfig-4.4.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9aacd7d93806b3f66b3ddc42ac0659cf",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.4",
"size": 7241,
"upload_time": "2023-04-06T20:28:49",
"upload_time_iso_8601": "2023-04-06T20:28:49.475559Z",
"url": "https://files.pythonhosted.org/packages/15/8f/40917dc40e82ecdee0009452b8fcb27e126cbfde975519e6f3086483af7f/bertdotconfig-4.4.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a213603a9ed6152a04e17d3356369cc7e173472718adbf4f391ad4b5a6014a47",
"md5": "38ba2ec55e6106e33d706f1c65712aa8",
"sha256": "692f8c8a66e16173c1a6de7fe9f2a7d164591ab76ca43aaecdaa8d976d71f7b8"
},
"downloads": -1,
"filename": "bertdotconfig-4.4.0.tar.gz",
"has_sig": false,
"md5_digest": "38ba2ec55e6106e33d706f1c65712aa8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.4",
"size": 9740,
"upload_time": "2023-04-06T20:28:50",
"upload_time_iso_8601": "2023-04-06T20:28:50.768660Z",
"url": "https://files.pythonhosted.org/packages/a2/13/603a9ed6152a04e17d3356369cc7e173472718adbf4f391ad4b5a6014a47/bertdotconfig-4.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-06 20:28:50",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "berttejeda",
"github_project": "bert.config",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"tox": true,
"lcname": "bertdotconfig"
}