Confuse - Jinja Variables
Simple Ansible-style variable parsing for Confuse config files using Jinja2.
Install
pip install confuse_jinja
Usage
import confuse_jinja
confuse_jinja.enable()
# now you can use jinja2 templates inside your keys
config = confuse.Configuration('asdf', read=False)
config.set({
'asdf': {
'blah': 'asdf{{ C.other.thing }}'
},
'nested': '{{ C.asdf }}',
'other': {'thing': 456}
})
assert config['asdf']['blah'].get() == 'asdf456'
assert config['nested'].get() == {'blah': 'asdf456'}
How it works
- for any config values that are a string, render it as a jinja2 template
- try to parse rendered string as python using ast functions graciously pulled from ansible's source code
- if a valid python object (list, dict, etc.) can be parsed from the string the object will be returned, otherwise it will return as a string.
TODO:
- test in a yaml file (possible syntax errors)
- enable on a config-by-config object basis instead of globally.
- would need to replace
ConfigView.__getitem__for a single Config - would require using
self.Subviewinstead of globalSubview
- would need to replace
Metadata
Release files for confuse-jinja 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| confuse_jinja-0.0.1.tar.gz | 3.9 kB | Without provenance | Details for confuse_jinja-0.0.1.tar.gz |
Release files / confuse_jinja-0.0.1.tar.gz
| Download URL | confuse_jinja-0.0.1.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
71cd0a37483faa356d38287bd626591148f9eaea20742144bc2f6c49fd616aa5
|
|
BLAKE2b-256 checksum How to use checksums |
d1c1269c3391e617ad42d79dcc6fe410fc9fdf07a138157ca59c846a86be9721
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.7
|
Security for confuse-jinja 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.