Enable variables in a TOML file
Project description
Overview
vartoml
allows using variables in TOML config files. It uses the toml
package.
Acknowledgent
The idea how to tackle the problem of variable interpolation was taken
from the envtoml
package which is at https://github.com/mrshu/envtoml .
Variable names in TOML file
Variables are specified this way: ${section[:section]:variable}
, i.e. sections can be nested.
Example usage
from vartoml import VarToml
TOML ="""
[default]
basedir = "/myproject"
bindir = "${default:basedir}/bin"
datadir = "${default:basedir}/data"
[other_dirs-sub]
logdir = "${default:datadir}/logs"
"""
toml = VarToml()
toml.loads(TOML)
assert toml.get('other_dirs-sub', 'logdir') == '/myproject/data/logs'
API
VarToml.load(f, _dict=dict)
same like what the toml package offers
VarToml.loads(s, _dict=dict)
same like what the toml package offers
VarToml.get(v,... )
returns a specific value from the toml dictionary
Example:
```python
toml = VarToml()
toml.loads('some.toml')
val = toml.get('default', 'id' )
```
VarToml.toml()
returns the dictionary of the parsed toml data
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
vartoml-0.9.7.tar.gz
(3.1 kB
view details)
Built Distribution
File details
Details for the file vartoml-0.9.7.tar.gz
.
File metadata
- Download URL: vartoml-0.9.7.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92c329d4120e7f788fba35bd223652c0dcc3d1795019e0eda6b33b28eb3afd9b |
|
MD5 | a0828ac9a6b5e13b218ddf57f4d12468 |
|
BLAKE2b-256 | a0729affde731095a9bb8ae308d72d0e3b698c22629bdc5e89c26f8179de0c03 |
File details
Details for the file vartoml-0.9.7-py3-none-any.whl
.
File metadata
- Download URL: vartoml-0.9.7-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab16d664b2c6de7fdccb276099a980e562676707511ba631a3ad794e7c233432 |
|
MD5 | b11bb929cf43ba2886bf28afce0d58fd |
|
BLAKE2b-256 | a3b974a8d38461ce417f15af35eafb3d5db326cbbf8a2cca1a9e66c0a383a9ae |