vutils-yaml: Working with YAML Format
This package provides tools for loading data from and saving data to the YAML format. Features:
- It annotates data while loading them from the YAML format. Every object
returned by
vutils.yaml.load.load_yamlhas information about its origin. This is useful when reporting errors.
Limitations:
- Due to the annotating data, this packages is not suitable for loading YAML formatted data containing thousands and hundreds of thousands items. For such amounts of data use PyYAML or other YAML parser since it is supposed that large data sets are usually machine-generated and consistent so further verification is not required.
- When used for the first time,
vutils.yaml.utils.keylocfunction builds a mapping betweendictkeys and their locations. This can be a bottle-neck for large dictionaries.
Due to the limitations, this package is suitable for parsing human-written configurations in YAML format containing at most hundreds of items.
Installation
pip install vutils-yaml
How to Use
Topic covered in this short guide is:
- loading annotated YAML data
- API reference
Loading Annotated YAML Data
To load YAML data with annotations, use the load_yaml function from
vutils.yaml.load. Example:
from vutils.yaml.load import load_yaml
from vutils.yaml.utils import is_null, keyloc
stream = """
---
food:
fruit:
- apple
- banana
- orange
vegetable:
- potato
- tomato
- carrot
meat: null
"""
data = load_yaml(stream)
food = data["food"]
# `if food["meat"] is None` will not work, `null` is converted to `NullType`
# object to be annotated
if is_null(food["meat"]):
# `keyloc` retrieves the annotated key object from `food` and return its
# location
print(f"{keyloc(food, 'meat')}: At least one kind of meat is required.")
Observe the testing if the value is null and the retrieving the meat key
location to inform a user where the problem with his/her data is.
API Reference
Module vutils.yaml.load provide these functions:
load_yaml(stream)loads YAML data fromstreamand annotates them.streamcan bestr,bytes, or afile-like object supportingread.
Module vutils.yaml.utils provide these functions:
getloc(obj)retrieves the location ofobjkeyloc(obj, kobj)retrieves the location ofkobj, which is a key ofdict-like objectobj.is_null(obj)tests whetherobjisnull.is_bool(obj)tests whetherobjis of the Boolean type.
Metadata
Release files for vutils-yaml 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 |
|---|---|---|---|---|
| vutils-yaml-0.1.4.tar.gz | 16.1 kB | Without provenance | Details for vutils-yaml-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| vutils_yaml-0.1.4-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for vutils_yaml-0.1.4-py2.py3-none-any.whl |
Total release size: 25.8 kB
Release files / vutils-yaml-0.1.4.tar.gz
| Download URL | vutils-yaml-0.1.4.tar.gz |
|---|---|
| Size | 16.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
268a8d87682529873c627efe3f5f44e0fc60fa12c23f53ced289fd764c44a5c8
|
|
BLAKE2b-256 checksum How to use checksums |
9ddf2c574d916937c59df66cc5314ef467bb5763242fee1c9641c59275e389ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.3
|
Release files / vutils_yaml-0.1.4-py2.py3-none-any.whl
| Download URL | vutils_yaml-0.1.4-py2.py3-none-any.whl |
|---|---|
| Size | 9.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
39cdf59bffbc0e636c88e834ad429144fe99c5b41ff2a714b4c36926fc78f331
|
|
BLAKE2b-256 checksum How to use checksums |
fcd85a40ea31cb33f407f1dd9251ad5781c13f9b408328ab1049fb555d53c10f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.11.3
|
Security for vutils-yaml 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.