yachain
YAML access on chained attribute names.
Install
$ pip install yachain
Suppose we have:
---
# config
network:
name: developers
gitserver:
ip: 192.168.178.101
netmask: 255.255.255.0
gateway: 192.168.178.1
packages:
- yum
- gcc
With yachain we can access this as:
>>> import yachain
>>> c = yachain.Config().load("netw.cfg")
>>> print(c["network::gitserver::gateway"])
192.168.178.1
>>> print(c["network::gitserver::packages"])
['yum', 'gcc']
References to files / paths independent from environment
References to files and paths can be used relative and absolute. In case an attribute ends on path or file then the path can be prefixed automatically when operation from a virtual environment is detected. The works by default upper and lower case and can be overriden.
Using the prefix makes it possible to use the same config in different environments.
import yachain
import yaml
import sys
import os
# yaml config:
yc = """
---
app:
logfile: var/log/app.log
textrules: var/app.app.txt
database_path: var/app/db
database_file: /var/app/db/db.txt
database_name: db.txt
"""
PREFIX = "/" if not hasattr(sys, 'real_prefix') else sys.prefix
# CONFIG_FILE = os.path.join(PREFIX, "etc/app/app.cfg")
config = yachain.Config(prefix=PREFIX, configdata=yaml.load(yc))
for A in ["logfile",
"textrules",
"database_path",
"database_file",
"database_name"]:
k = "app::{}".format(A)
print config[k]
When run from a virtual environment, this will give us:
/home/user/venv/var/log/app.log
var/app.app.txt
/home/user/venv/var/app/db
/var/app/db/db.txt
db.txt
So, as expected, the logfile and database_path got the PREFIX.
When run from a non-virtual environment, this will give us:
/var/log/app.log
var/app.app.txt
/var/app/db
/var/app/db/db.txt
db.txt
So, as expected, prefixed with “/”.
Metadata
Release files for yachain 0.1.4
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 |
|---|---|---|---|---|
| yachain-0.1.4.tar.gz | 5.2 kB | Without provenance | Details for yachain-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| yachain-0.1.4-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for yachain-0.1.4-py2.py3-none-any.whl |
Total release size: 11.6 kB
Release files / yachain-0.1.4.tar.gz
| Download URL | yachain-0.1.4.tar.gz |
|---|---|
| Size | 5.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f5cbad2ccae848daa88a064b809494a52ca1c8ea49dbea20c548b46ff26959fb
|
|
BLAKE2b-256 checksum How to use checksums |
8b1e09a604ac7a50cb84a247ef69818cee973978f8e2bb55b93818ae08d221f7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.12.4 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.5.2
|
Release files / yachain-0.1.4-py2.py3-none-any.whl
| Download URL | yachain-0.1.4-py2.py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
5a3688fb08697fd7f8ff69892d37e8df225e4d85d0ba8f66db37ef1fa090be24
|
|
BLAKE2b-256 checksum How to use checksums |
9d89572e2b36353afb052caf2887667c084950bc3fea2be65e37d080a39ab493
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.12.4 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.5.2
|
Security for yachain 0.1.4
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.