Easy dot representation configuration module.
Project description
dconf
or DotConf
Make Config Great Again.
Easy dot representation configuration module to make config life better.
How to use
Example:
config.toml
title = "TOML Example"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00
[database]
enabled = true
ports = [ 8000, 8001, 8002 ]
data = [ ["delta", "phi"], [3.14] ]
temp_targets = { cpu = 79.5, case = 72.0 }
[servers]
[servers.alpha]
ip = "10.0.0.1"
role = "frontend"
[servers.beta]
ip = "10.0.0.2"
role = "backend"
[[products]]
name = "Hammer"
sku = 738594937
[[products]]
name = "Nail"
sku = 284758393
>>> import tomli
... from dotconfig import DotConfig
... CONFIG = DotConfig()
... CONFIG.load(tomli.load, "config.toml")
>>> CONFIG
{'title': 'TOML Example', 'owner': {'name': 'Tom Preston-Werner', 'dob': datetime.datetime(1979, 5, 27, 7, 32, tzinfo=datetime.timezone(datetime.timedelta(days=-1, seconds=57600)))}, 'database': {'enabled': True, 'ports': [8000, 8001, 8002], 'data': [['delta', 'phi'], [3.14]], 'temp_targets': {'cpu': 79.5, 'case': 72.0}}, 'servers': {'alpha': {'ip': '10.0.0.1', 'role': 'frontend'}, 'beta': {'ip': '10.0.0.2', 'role': 'backend'}}, 'products': [{'name': 'Hammer', 'sku': 738594937}, {'name': 'Nail', 'sku': 284758393}]}
>>> CONFIG.title
'TOML Example'
>>> CONFIG.database.ports
[8000, 8001, 8002]
>>> CONFIG.database.temp_targets.cpu
79.5
>>> CONFIG.servers
{'alpha': {'ip': '10.0.0.1', 'role': 'frontend'}, 'beta': {'ip': '10.0.0.2', 'role': 'backend'}}
>>> CONFIG.servers.alpha.role
'frontend'
>>> CONFIG.products
[{'name': 'Hammer', 'sku': 738594937}, {'name': 'Nail', 'sku': 284758393}]
>>> CONFIG.products[0].sku
738594937
Another way to load the configuration
>>> config = {'alpha': {'ip': '10.0.0.1', 'role': 'frontend'}, 'beta': {'ip': '10.0.0.2', 'role': 'backend'}}
... CONFIG = DotConfig(config)
>>> CONFIG.beta.ip
'10.0.0.2'
Contribute
Feel free to fork and pr.
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
dconf-0.0.3.tar.gz
(3.3 kB
view details)
File details
Details for the file dconf-0.0.3.tar.gz
.
File metadata
- Download URL: dconf-0.0.3.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af7296c72d4363fe61294cf05eb52d8f26efdf436f6059e02a4792a4490450f2 |
|
MD5 | d39de399d33c369e181d9a4b35aeaac5 |
|
BLAKE2b-256 | a2bee42ad5b1a0fab0717eee541588f13c202f9a6e5212b8d4017f144c233124 |