<img align="right" src="https://raw.github.com/cliffano/cfg-rw/main/avatar.jpg" alt="Avatar"/>
[![Build Status](https://github.com/cliffano/cfg-rw/workflows/CI/badge.svg)](https://github.com/cliffano/cfg-rw/actions?query=workflow%3ACI)
[![Security Status](https://snyk.io/test/github/cliffano/cfg-rw/badge.svg)](https://snyk.io/test/github/cliffano/cfg-rw)
[![Dependencies Status](https://img.shields.io/librariesio/release/pypi/cfgrw)](https://libraries.io/github/cliffano/cfg-rw)
[![Published Version](https://img.shields.io/pypi/v/cfgrw.svg)](https://pypi.python.org/pypi/cfgrw)
<br/>
CFG-RW
------
CFG-RW is a Python library for reading and writing properties in configuration files.
Installation
------------
pip3 install cfgrw
Usage
-----
### Configuration file
CFG-RW can read configuration properties from YAML, JSON, INI, and XML files.
Create a configuration file, e.g. `cfgrw.yaml`:
---
handlers: "stream,file"
datefmt: "%Y-%m-%d %H:%M:%S"
filename: "stage/test-integration/test-yaml-conf.log"
filemode: "w"
format: "%(levelname)s %(message)s"
level: "info"
Create CFGRW object with specific conf_file, and read the values of the configuration properties:
from cfgrw import CFGRW
cfgrw = CFGRW(conf_file='path/to/cfgrw.yaml')
values = cfgrw.read(['handlers', 'filemode', 'level'])
print(value['handlers']) # will print stream,file
print(value['filemode']) # will print w
print(value['level']) # will print info
### Environment variables
CFG-RW can also read configuration properties from environment variables with a given prefix.
For example, here are the environment variables with prefix `CFGRW_` :
export CFGRW_HANDLERS="stream,file"
export CFGRW_DATEFMT="%Y-%m-%d %H:%M:%S"
export CFGRW_FILENAME="stage/test-integration/test-yaml-conf.log"
export CFGRW_FILEMODE="w"
export CFGRW_FORMAT="%(levelname)s %(message)s"
export CFGRW_LEVEL="info"
Create CFGRW object without conf_file, and read the value of the configuration properties with specified prefix:
cfgrw = CFGRW()
values = cfgrw.read(['handlers', 'filemode', 'level'], { 'prefix': 'CFGRW_' })
print(value['handlers']) # will print stream,file
print(value['filemode']) # will print w
print(value['level']) # will print info
### Configuration file with Jinja template
CFG-RW can read configuration properties with YAML, JSON, INI, and XML within a Jinja template. You just need to add a `.j2` to the configuration file name.
Create a configuration Jinja template, e.g. `cfgrw.yaml.j2`:
---
handlers: "{{ env.FOOBAR_HANDLERS }}"
datefmt: "%Y-%m-%d %H:%M:%S"
filename: "stage/test-integration/test-yaml-conf.log"
filemode: "{{ env.FOOBAR_FILEMODE }}"
format: "%(levelname)s %(message)s"
level: "{{ env.FOOBAR_LEVEL }}"
and the following environment variables:
export FOOBAR_HANDLERS="stream,file"
export FOOBAR_FILEMODE="w"
export FOOBAR_LEVEL="info"
Create CFGRW object with specific conf_file, and read the values of the configuration properties:
from cfgrw import CFGRW
cfgrw = CFGRW(conf_file='path/to/cfgrw.yaml.j2')
values = cfgrw.read(['handlers', 'level', 'level'])
print(value['handlers']) # will print stream,file
print(value['filemode']) # will print w
print(value['level']) # will print info
Configuration
-------------
CFG-RW automatically loads the configuration file based on the extension.
| Format | Extension |
|--------|-----------|
| [INI](https://en.wikipedia.org/wiki/INI_file) | `.ini` |
| [JSON](https://www.json.org/) | `.json` |
| [XML](https://www.w3.org/XML/) | `.xml` |
| [YAML](https://yaml.org/) | `.yaml` or `.yml` |
| [Jinja](https://jinja.palletsprojects.com/en/stable/) | `.ini.j2` or `.json.j2` or `.xml.j2` or `.yaml.j2` or `.yml.j2` |
Colophon
--------
[Developer's Guide](https://cliffano.github.io/developers_guide.html#python)
Build reports:
* [Lint report](https://cliffano.github.io/cfgrw/lint/pylint/index.html)
* [Code complexity report](https://cliffano.github.io/cfgrw/complexity/wily/index.html)
* [Unit tests report](https://cliffano.github.io/cfgrw/test/pytest/index.html)
* [Test coverage report](https://cliffano.github.io/cfgrw/coverage/coverage/index.html)
* [Integration tests report](https://cliffano.github.io/cfgrw/test-integration/pytest/index.html)
* [API Documentation](https://cliffano.github.io/cfgrw/doc/sphinx/index.html)
Raw data
{
"_id": null,
"home_page": "https://github.com/cliffano/cfg-rw",
"name": "cfgrw",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.10",
"maintainer_email": null,
"keywords": "cfgrw, configuration",
"author": "Cliffano Subagio",
"author_email": "cliffano@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ff/22/0ee2d3bd6053e0982d728d23480c780e638850c86ac4743fa3d2d4375d76/cfgrw-0.10.1.tar.gz",
"platform": null,
"description": "<img align=\"right\" src=\"https://raw.github.com/cliffano/cfg-rw/main/avatar.jpg\" alt=\"Avatar\"/>\n\n[![Build Status](https://github.com/cliffano/cfg-rw/workflows/CI/badge.svg)](https://github.com/cliffano/cfg-rw/actions?query=workflow%3ACI)\n[![Security Status](https://snyk.io/test/github/cliffano/cfg-rw/badge.svg)](https://snyk.io/test/github/cliffano/cfg-rw)\n[![Dependencies Status](https://img.shields.io/librariesio/release/pypi/cfgrw)](https://libraries.io/github/cliffano/cfg-rw)\n[![Published Version](https://img.shields.io/pypi/v/cfgrw.svg)](https://pypi.python.org/pypi/cfgrw)\n<br/>\n\nCFG-RW\n------\n\nCFG-RW is a Python library for reading and writing properties in configuration files.\n\nInstallation\n------------\n\n pip3 install cfgrw\n\nUsage\n-----\n\n### Configuration file\n\nCFG-RW can read configuration properties from YAML, JSON, INI, and XML files.\n\nCreate a configuration file, e.g. `cfgrw.yaml`:\n\n ---\n handlers: \"stream,file\"\n datefmt: \"%Y-%m-%d %H:%M:%S\"\n filename: \"stage/test-integration/test-yaml-conf.log\"\n filemode: \"w\"\n format: \"%(levelname)s %(message)s\"\n level: \"info\"\n\nCreate CFGRW object with specific conf_file, and read the values of the configuration properties:\n\n from cfgrw import CFGRW\n\n cfgrw = CFGRW(conf_file='path/to/cfgrw.yaml')\n values = cfgrw.read(['handlers', 'filemode', 'level'])\n print(value['handlers']) # will print stream,file\n print(value['filemode']) # will print w\n print(value['level']) # will print info\n\n### Environment variables\n\nCFG-RW can also read configuration properties from environment variables with a given prefix.\n\nFor example, here are the environment variables with prefix `CFGRW_` :\n\n export CFGRW_HANDLERS=\"stream,file\"\n export CFGRW_DATEFMT=\"%Y-%m-%d %H:%M:%S\"\n export CFGRW_FILENAME=\"stage/test-integration/test-yaml-conf.log\"\n export CFGRW_FILEMODE=\"w\"\n export CFGRW_FORMAT=\"%(levelname)s %(message)s\"\n export CFGRW_LEVEL=\"info\"\n\nCreate CFGRW object without conf_file, and read the value of the configuration properties with specified prefix:\n\n cfgrw = CFGRW()\n values = cfgrw.read(['handlers', 'filemode', 'level'], { 'prefix': 'CFGRW_' })\n print(value['handlers']) # will print stream,file\n print(value['filemode']) # will print w\n print(value['level']) # will print info\n\n### Configuration file with Jinja template\n\nCFG-RW can read configuration properties with YAML, JSON, INI, and XML within a Jinja template. You just need to add a `.j2` to the configuration file name.\n\nCreate a configuration Jinja template, e.g. `cfgrw.yaml.j2`:\n\n ---\n handlers: \"{{ env.FOOBAR_HANDLERS }}\"\n datefmt: \"%Y-%m-%d %H:%M:%S\"\n filename: \"stage/test-integration/test-yaml-conf.log\"\n filemode: \"{{ env.FOOBAR_FILEMODE }}\"\n format: \"%(levelname)s %(message)s\"\n level: \"{{ env.FOOBAR_LEVEL }}\"\n\nand the following environment variables:\n\n export FOOBAR_HANDLERS=\"stream,file\"\n export FOOBAR_FILEMODE=\"w\"\n export FOOBAR_LEVEL=\"info\"\n\nCreate CFGRW object with specific conf_file, and read the values of the configuration properties:\n\n from cfgrw import CFGRW\n\n cfgrw = CFGRW(conf_file='path/to/cfgrw.yaml.j2')\n values = cfgrw.read(['handlers', 'level', 'level'])\n print(value['handlers']) # will print stream,file\n print(value['filemode']) # will print w\n print(value['level']) # will print info\n\nConfiguration\n-------------\n\nCFG-RW automatically loads the configuration file based on the extension.\n\n| Format | Extension |\n|--------|-----------|\n| [INI](https://en.wikipedia.org/wiki/INI_file) | `.ini` |\n| [JSON](https://www.json.org/) | `.json` |\n| [XML](https://www.w3.org/XML/) | `.xml` |\n| [YAML](https://yaml.org/) | `.yaml` or `.yml` |\n| [Jinja](https://jinja.palletsprojects.com/en/stable/) | `.ini.j2` or `.json.j2` or `.xml.j2` or `.yaml.j2` or `.yml.j2` |\n\nColophon\n--------\n\n[Developer's Guide](https://cliffano.github.io/developers_guide.html#python)\n\nBuild reports:\n\n* [Lint report](https://cliffano.github.io/cfgrw/lint/pylint/index.html)\n* [Code complexity report](https://cliffano.github.io/cfgrw/complexity/wily/index.html)\n* [Unit tests report](https://cliffano.github.io/cfgrw/test/pytest/index.html)\n* [Test coverage report](https://cliffano.github.io/cfgrw/coverage/coverage/index.html)\n* [Integration tests report](https://cliffano.github.io/cfgrw/test-integration/pytest/index.html)\n* [API Documentation](https://cliffano.github.io/cfgrw/doc/sphinx/index.html)\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Python library for reading and writing properties in configuration files",
"version": "0.10.1",
"project_urls": {
"Documentation": "https://github.com/cliffano/cfg-rw",
"Homepage": "https://github.com/cliffano/cfg-rw",
"Repository": "https://github.com/cliffano/cfg-rw"
},
"split_keywords": [
"cfgrw",
" configuration"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "050a74b323caa099810934cd5c3294b9facb42ecaeb54db8e266cd75581174fd",
"md5": "8141588b3188869bcdf41a05318bb0b9",
"sha256": "99dc0f01b394db35edd4457be05cb4c98393a414217b814340379314657cd183"
},
"downloads": -1,
"filename": "cfgrw-0.10.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8141588b3188869bcdf41a05318bb0b9",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.10",
"size": 10165,
"upload_time": "2024-11-07T23:25:40",
"upload_time_iso_8601": "2024-11-07T23:25:40.156540Z",
"url": "https://files.pythonhosted.org/packages/05/0a/74b323caa099810934cd5c3294b9facb42ecaeb54db8e266cd75581174fd/cfgrw-0.10.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ff220ee2d3bd6053e0982d728d23480c780e638850c86ac4743fa3d2d4375d76",
"md5": "bf5266cf0f53e415b506df49b1c9786a",
"sha256": "60c3da6a50971961f957d6465b1b7bad4d7b04e2ce60e6c986327b1d8f3881c8"
},
"downloads": -1,
"filename": "cfgrw-0.10.1.tar.gz",
"has_sig": false,
"md5_digest": "bf5266cf0f53e415b506df49b1c9786a",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.10",
"size": 7950,
"upload_time": "2024-11-07T23:25:41",
"upload_time_iso_8601": "2024-11-07T23:25:41.878970Z",
"url": "https://files.pythonhosted.org/packages/ff/22/0ee2d3bd6053e0982d728d23480c780e638850c86ac4743fa3d2d4375d76/cfgrw-0.10.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-07 23:25:41",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "cliffano",
"github_project": "cfg-rw",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"lcname": "cfgrw"
}