Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fmenabe/python-yamlordereddictloader
(DEPRECATED) YAML loader and dumper for PyYAML allowing to keep keys order.
https://github.com/fmenabe/python-yamlordereddictloader
dumper keep-order loader ordered ordereddict python yaml
Last synced: about 2 months ago
JSON representation
(DEPRECATED) YAML loader and dumper for PyYAML allowing to keep keys order.
- Host: GitHub
- URL: https://github.com/fmenabe/python-yamlordereddictloader
- Owner: fmenabe
- License: mit
- Created: 2014-06-13T16:04:14.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2023-09-22T13:52:39.000Z (over 1 year ago)
- Last Synced: 2024-04-24T08:28:16.706Z (8 months ago)
- Topics: dumper, keep-order, loader, ordered, ordereddict, python, yaml
- Language: Python
- Homepage:
- Size: 12.7 KB
- Stars: 26
- Watchers: 6
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGELOG.rst
- License: LICENSE.txt
Awesome Lists containing this project
README
python-yamlordereddictloader
============================**DEPRECATED: the** `Phynix/yamlloader `_ **project
provide an improved version of this library with unit tests, performance improvements
(by providing access to the C implementation of PyYAML) and is more actively developed.
You should use it!**.. image:: https://img.shields.io/pypi/l/yamlordereddictloader.svg
:target: https://opensource.org/licenses/MIT
:alt: License.. image:: https://img.shields.io/pypi/pyversions/yamlordereddictloader.svg
:target: https://pypi.python.org/pypi/yamlordereddictloader
:alt: Versions.. image:: https://img.shields.io/pypi/v/yamlordereddictloader.svg
:target: https://pypi.python.org/pypi/yamlordereddictloader
:alt: PyPi.. image:: https://img.shields.io/badge/github-repo-yellow.jpg
:target: https://github.com/fmenabe/python-yamlordereddictloader
:alt: Code repo.. image:: https://landscape.io/github/fmenabe/python-yamlordereddictloader/master/landscape.svg?style=flat
:target: https://landscape.io/github/fmenabe/python-yamlordereddictloader/master
:alt: Code HealthThis module provide a loader and a dumper for PyYAML allowing to keep items order
when loading a file (by putting them in ``OrderedDict`` objects) and to manage
``OrderedDict`` objects when dumping to a file.The loader is based on stackoverflow topic (thanks to Eric Naeseth):
http://stackoverflow.com/questions/5121931/in-python-how-can-you-load-yaml-mappings-as-ordereddicts#answer-5121963Self promotion: I use it a lot with `clg `_, which
allows to generate command-line definition from a configuration file, for keeping
order of subcommands, options and arguments in the help message!To install it
-------------.. code-block:: bash
$ pip install yamlordereddictloader
Loader usage
------------.. code-block:: python
import yaml
import yamlordereddictloaderdata = yaml.load(open('myfile.yml'), Loader=yamlordereddictloader.Loader)
**Note:** For using the safe loader (which want standard YAML tags and does
not construct arbitrary Python objects), replace ``yamlorderdictloader.Loader`` by
``yamlorderedictloader.SafeLoader``.Dumper usage
------------.. code-block:: python
import yaml
import yamlordereddictloader
from collections import OrderedDictdata = OrderedDict([
('key1', 'val1'),
('key2', OrderedDict([('key21', 'val21'), ('key22', 'val22')]))
])
yaml.dump(
data,
open('myfile.yml', 'w'),
Dumper=yamlordereddictloader.Dumper,
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``.