btconfig


Namebtconfig JSON
Version 4.5.0 PyPI version JSON
download
home_pagehttps://github.com/berttejeda/bert.config
SummaryModule for reading configuration files
upload_time2023-07-19 23:50:27
maintainer
docs_urlNone
authorEngelbert Tejeda
requires_python>=3.4
license
keywords yaml configuration config file python settings
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <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 btconfig`
* 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 btconfig 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 btconfig 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 btconfig 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": "btconfig",
    "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/6a/bb/d3d639f6309545916e0b091e90f4f554d5707b409796f2e0194252ab55cb/btconfig-4.5.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 btconfig`\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 btconfig 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 btconfig 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 btconfig 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.5.0",
    "project_urls": {
        "Homepage": "https://github.com/berttejeda/bert.config"
    },
    "split_keywords": [
        "yaml",
        "configuration",
        "config",
        "file",
        "python",
        "settings"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2069c4fc9098cd29090b7285541166d57a58080a1bfb555d65fd74afc7339b0f",
                "md5": "dbe1722d49098cc30ede8e3e34ac182f",
                "sha256": "326d3f96c816e634a49f3cfb606da2aa7377dcb88a7c14fbc7e8615e1822969e"
            },
            "downloads": -1,
            "filename": "btconfig-4.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "dbe1722d49098cc30ede8e3e34ac182f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.4",
            "size": 7184,
            "upload_time": "2023-07-19T23:50:26",
            "upload_time_iso_8601": "2023-07-19T23:50:26.405172Z",
            "url": "https://files.pythonhosted.org/packages/20/69/c4fc9098cd29090b7285541166d57a58080a1bfb555d65fd74afc7339b0f/btconfig-4.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6abbd3d639f6309545916e0b091e90f4f554d5707b409796f2e0194252ab55cb",
                "md5": "74622a06aaedca3e8b052774fed22de7",
                "sha256": "a930ed317f1c0a1ca3f3e5f40e0f06f5ffcc5c680e661edbe6ed967c48562e49"
            },
            "downloads": -1,
            "filename": "btconfig-4.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "74622a06aaedca3e8b052774fed22de7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.4",
            "size": 9900,
            "upload_time": "2023-07-19T23:50:27",
            "upload_time_iso_8601": "2023-07-19T23:50:27.799755Z",
            "url": "https://files.pythonhosted.org/packages/6a/bb/d3d639f6309545916e0b091e90f4f554d5707b409796f2e0194252ab55cb/btconfig-4.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-19 23:50:27",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "berttejeda",
    "github_project": "bert.config",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "tox": true,
    "lcname": "btconfig"
}
        
Elapsed time: 0.35278s