# CONFINI
Configuration parser that process all sections and values in all `ini` files in a directory.
## Usage
```
import confini
c = confini.Config('/path/to/config/dir')
c.process()
print(c.get('FOO_BAR_BAZ'))
```
### Value storage
The values are stored in a single key/value dictionary, with section and name separated by _underscore_ and all letters transformed to uppercase.
Consider this value in an ini section:
```
[foO]
bar_baz = 42
```
This will be stored in the `confini` store with `FOO_BAR_BAZ` as the key.
### Environment overrides
By default, the value of any environment variable matching a store key will overwrite the corresponding value in the store.
A prefix can be provided on instantiation to define a separate namespace for environment variable overrides:
```
>>> os.environ.set('FOO_BAZ_BAZ', 666)
>>> c = config.Config('/path/to/config/dir')
>>> c.process()
>>> print(c.get('FOO_BAR_BAZ'))
666
>>> c = config.Config('/path/to/config/dir', 'XXX')
>>> c.process()
>>> print(c.get('FOO_BAR_BAZ'))
42
>>> os.environ.set('XXX_FOO_BAZ_BAZ', 13)
>>> c = config.Config('/path/to/config/dir', 'XXX')
>>> c.process()
>>> print(c.get('FOO_BAR_BAZ'))
13
```
### Required values
Keys can be set as required, and after processing independently validated:
```
>>> c = config.Config('/path/to/config/dir')
>>> c.require('BAR_BAZ', 'FOO')
>>> c.process()
>>> c.validate()
True
>>> c = config.Config('/path/to/config/dir')
>>> c.require('BAR_BAZ_BAZ', 'FOO')
>>> c.process()
>>> c.validate()
False
```
### Censoring logs
The string representation of the confini object is a list of all stored values, one on each line.
Display of individual values can be suppressed:
```
>>> c = config.Config('/path/to/config/dir')
>>> c.process()
>>> print(c)
FOO_BAR_BAZ = 666
>>> c.censor('BAR_BAZ', 'FOO')
>>> print(c)
***
```
### Encryption
Values can be **GNUPG** encrypted by saving them in individual encrypted files providing the filename as value argument wrapped in a gpg directve:
```
[foo]
BAR_BAZ = !gpg(foo_bar_baz.asc)
```
Decryption mode is on by default, and can be deactivated on instantiation:
```
>>> c = config.Config('/path/to/config/dir')
>>> c.process()
>>> c.get()
666
>>> c = config.Config('/path/to/config/dir', decrypt=False)
>>> c.process()
>>> c.get()
!gpg(foo_bar_baz.asc)
```
The user keyring in the default location is used for decryption, which may be overridden as usual with the `GNUPGHOME` environment variable.
Raw data
{
"_id": null,
"home_page": "https://gitlab.com/nolash/python-confini",
"name": "confini",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Louis Holbrook",
"author_email": "dev@holbrook.no",
"download_url": "https://files.pythonhosted.org/packages/f2/13/1f78bb54bf706dc32c01f270b1e9e299e226b97ff13cc999a88350a39d78/confini-0.6.5.tar.gz",
"platform": null,
"description": "# CONFINI\n\nConfiguration parser that process all sections and values in all `ini` files in a directory.\n\n## Usage\n\n``` \nimport confini\n\nc = confini.Config('/path/to/config/dir')\nc.process()\n\nprint(c.get('FOO_BAR_BAZ'))\n\n```\n\n### Value storage\n\nThe values are stored in a single key/value dictionary, with section and name separated by _underscore_ and all letters transformed to uppercase.\n\nConsider this value in an ini section:\n\n```\n[foO]\nbar_baz = 42\n```\n\nThis will be stored in the `confini` store with `FOO_BAR_BAZ` as the key.\n\n### Environment overrides\n\nBy default, the value of any environment variable matching a store key will overwrite the corresponding value in the store.\n\nA prefix can be provided on instantiation to define a separate namespace for environment variable overrides:\n\n```\n>>> os.environ.set('FOO_BAZ_BAZ', 666)\n>>> c = config.Config('/path/to/config/dir')\n>>> c.process()\n>>> print(c.get('FOO_BAR_BAZ'))\n666\n>>> c = config.Config('/path/to/config/dir', 'XXX')\n>>> c.process()\n>>> print(c.get('FOO_BAR_BAZ'))\n42\n>>> os.environ.set('XXX_FOO_BAZ_BAZ', 13)\n>>> c = config.Config('/path/to/config/dir', 'XXX')\n>>> c.process()\n>>> print(c.get('FOO_BAR_BAZ'))\n13\n```\n\n### Required values\n\nKeys can be set as required, and after processing independently validated:\n\n```\n>>> c = config.Config('/path/to/config/dir')\n>>> c.require('BAR_BAZ', 'FOO')\n>>> c.process()\n>>> c.validate()\nTrue\n>>> c = config.Config('/path/to/config/dir')\n>>> c.require('BAR_BAZ_BAZ', 'FOO')\n>>> c.process()\n>>> c.validate()\nFalse\n```\n\n### Censoring logs\n\nThe string representation of the confini object is a list of all stored values, one on each line.\n\nDisplay of individual values can be suppressed:\n\n```\n>>> c = config.Config('/path/to/config/dir')\n>>> c.process()\n>>> print(c)\nFOO_BAR_BAZ = 666\n>>> c.censor('BAR_BAZ', 'FOO')\n>>> print(c)\n***\n```\n\n### Encryption\n\nValues can be **GNUPG** encrypted by saving them in individual encrypted files providing the filename as value argument wrapped in a gpg directve:\n\n```\n[foo]\nBAR_BAZ = !gpg(foo_bar_baz.asc)\n```\n\nDecryption mode is on by default, and can be deactivated on instantiation:\n\n```\n>>> c = config.Config('/path/to/config/dir')\n>>> c.process()\n>>> c.get()\n666\n>>> c = config.Config('/path/to/config/dir', decrypt=False)\n>>> c.process()\n>>> c.get()\n!gpg(foo_bar_baz.asc)\n```\n\nThe user keyring in the default location is used for decryption, which may be overridden as usual with the `GNUPGHOME` environment variable.\n\n\n",
"bugtrack_url": null,
"license": "WTFPL",
"summary": "Parse, verify and merge all ini files in a single directory",
"version": "0.6.5",
"project_urls": {
"Homepage": "https://gitlab.com/nolash/python-confini"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f2131f78bb54bf706dc32c01f270b1e9e299e226b97ff13cc999a88350a39d78",
"md5": "cdf2d930299c7cb2c0de641e959b1b65",
"sha256": "0fff362f46c152d35c93c5cd8904d9de7c37185f73a548bd56ebc6bc9c6ba0ab"
},
"downloads": -1,
"filename": "confini-0.6.5.tar.gz",
"has_sig": false,
"md5_digest": "cdf2d930299c7cb2c0de641e959b1b65",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 13231,
"upload_time": "2023-08-19T15:41:07",
"upload_time_iso_8601": "2023-08-19T15:41:07.799025Z",
"url": "https://files.pythonhosted.org/packages/f2/13/1f78bb54bf706dc32c01f270b1e9e299e226b97ff13cc999a88350a39d78/confini-0.6.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-19 15:41:07",
"github": false,
"gitlab": true,
"bitbucket": false,
"codeberg": false,
"gitlab_user": "nolash",
"gitlab_project": "python-confini",
"lcname": "confini"
}