Lord of the Config is a super-simple YAML-based configuration system. No more meaningless key-checking or file creation. LOTConfig makes it easy to create, manage, and write configurations.
Repository: https://bitbucket.org/bear_belly/lord_of_the_config
## Examples
Here are some quick-and-dirty examples for how the engine works:
Python 3.6.3 (default, Oct 3 2017, 21:45:48)
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from lotconfig import Config
>>> config = Config.load_or_create("sample.yaml")
>>> config['basic/thing']
'my_value'
## Loading a config
Configs are loaded from YAML files. To load a config use the Config.load, method or–better yet–the Config.load_or_create() method for fool-proof config loading. This will create the file if it doesn’t exist.
## Accessing config values
To access configuration values, you can either use config.get() or dict-like access:
# This will return “default_value” if nothing is set in ‘/path/to/param’ config.get(‘path/to/param’, ‘default_value’) # This will just return None if nothing is set in ‘/path/to/param’ config[‘/path/to/param’]
You can use typical dict functions, too, like in.
## Setting Configuration Values
Woah, there tiger! Unfortunately this isn’t implemented yet. Since LOTConfig implements advanced features (see below), setting a configruation value is pretty intensive.
Hopefully it’ll happen in the future.
In the meantime you’ll be greeted with an Exception if you try to do this.
## Writing a configuration
To write a configuration, call config.write() or config.write_stream().
## Advanced features
### Modes
Modes are special keywords in the yaml configuration.
There’s a default keyword you can specify at the beginning of the file to specify a mode. For example:
mode: development
This mode can be used throughout the file to specify different environments. For the mode value, prefix it with ‘@’ (and make sure to surround it with quotes, since YAML doesn’t like ‘@’ for keys). For example:
- server:
- ‘@development’:
host: localhost port: 5000
- ‘@production’:
host: example.com port: 5000
This way, whenever mode is 'production', you can refer server will automatically refer to {host: "example.com", "port": 5000}, and if mode is set to developemnt, then server will refer to {host: "localhost", "port": 5000}.
IMPORTANT. These mode keys are essentially invisible. You can’t force the configuation to read config['server/@development/host'].
So if mode is production config['server/host'] is example.com. If mode is development config['server/host'] is localhost.
### References
Don’t repeat yourself. You can refer to another value within the config using a key reference. Key references are strings that refer to other config values.
References are preceded with a tilde (~).
Consider the following example:
- database:
home: ~server1 remote: ~server2
- hardware:
- servers:
server1: 192.168.0.1 server2: 192.168.0.2
This would result in the following configuration:
- >> config[‘database/home’]
‘192.168.0.1’
- >> config[‘database/remote’]
‘192.16.0.2’
See? References help you to reduce the amount you have to type. You can even use it for complex configurations:
- letter_a:
category_a: ~cat_a category_b: ~cat_b
- letter_b:
- cat_a:
item_a: 1 item_b: false
- cat_b:
item_a: 19 item_b: 20
This would result in the following configuration:
- >> config[‘letter_a/category_a’]
{‘item_a’: 1, ‘item_b’: false}
### evals
Evals are probably the most powerful fo the bunch. They evaluate raw Python code. As such, use LOTConfig only on configuration files you trust. In future versions a paramter may be passed to turn on evaluations.
Evals begin with the keyword eval>>. The result is always a raw string. For example:
key: eval>> 1+2 # results in config[‘key’] -> ‘3’
Two modules are available to be evaluated: os and env.
key: eval>> os.environ[‘DISPLAY’] # results in config[‘key’] -> ‘:0’
Home-page: UNKNOWN Author: Jordan Hewitt Author-email: jordan.h@startmail.com License: GPLv3 Description-Content-Type: UNKNOWN Description: UNKNOWN Platform: UNKNOWN
Metadata
Release files for lotconfig 1.3
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 |
|---|---|---|---|---|
| lotconfig-1.3.linux-x86_64.tar.gz | 7.3 kB | Without provenance | Details for lotconfig-1.3.linux-x86_64.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lotconfig-1.3-py3-none-any.whl | Python 3 | none | any | Details for lotconfig-1.3-py3-none-any.whl |
Total release size: 15.6 kB
Release files / lotconfig-1.3.linux-x86_64.tar.gz
| Download URL | lotconfig-1.3.linux-x86_64.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5b346c1440f1edb412cdf1ab89d98ffd00c59607ff48dcfc176c139facc7217a
|
|
BLAKE2b-256 checksum How to use checksums |
0d6a40acccc183168e276c29c452977c46662a756afa8846c9730420f0b3751b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / lotconfig-1.3-py3-none-any.whl
| Download URL | lotconfig-1.3-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
643f6d4f2d811c734a296657d8299ee12d312ca80803d9250d5398fcd40785ed
|
|
BLAKE2b-256 checksum How to use checksums |
7b5e0ceaef626b3e9dcf497ad6cb5d9e779780f4ffeaeb4eceb397bad513444b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for lotconfig 1.3
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.