YAML loader and dumper for PyYAML allowing to keep keys order.
Project description
yamlloader
This project was mirrored from yamlordereddict Many thanks to the original author François Ménabé! It contains several improvements including the much faster C-versions of the Loaders/Dumpers.
This module provides loaders and dumpers for PyYAML. Currently, an OrderedDict loader/dumper is implemented, allowing to keep items order when loading resp. dumping a file from/to an OrderedDict.
Install
It is recommended to use the pip or anaconda version
$ pip install yamlloader
or
$ conda install yamlloader -c phynix
But does [your special case here] also work?
Tests are run continuously using randomly generated yaml files. Also, there are no fails to be expected.
Still, if you are concerned that your special case may breaks in the future, please add your own tests as test_ext_anyname.py under tests/ or let us know about your needs. This guarantees that no code will be added that breaks your case.
Loader usage
import yaml
import yamlloader
data = yaml.load(open('myfile.yml'), Loader=yamlloader.ordereddict.CLoader) # CLoader is faster than Loader
Note: For using the safe loader (which takes standard YAML tags and does not construct arbitrary Python objects), replace yamlorderdictloader.CLoader by yamlorderedictloader.CSafeLoader.
Dumper usage
import yaml
import yamlloader
from collections import OrderedDict
data = OrderedDict([
('key1', 'val1'),
('key2', OrderedDict([('key21', 'val21'), ('key22', 'val22')]))
])
yaml.dump(data,
open('myfile.yml', 'w'),
Dumper=yamlloader.ordereddict.CDumper,
default_flow_style=False)
Note: For using the safe dumper (which produce standard YAML tags and does not represent arbitrary Python objects), replace yamlorderdictloader.Dumper by yamlorderedictloader.SafeDumper.
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
File details
Details for the file yamlloader-0.5.0.tar.gz
.
File metadata
- Download URL: yamlloader-0.5.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d9cad95e01aad1188bd4144dabd0cc682eb9b0c5b4ea3ac11845b734f8ae254 |
|
MD5 | 110c351c386851f599be670c04680c09 |
|
BLAKE2b-256 | c51bac3879d7a012978dfb79985783ef77ea43e91a993133577760ed075821e6 |