Skip to main content

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!

License Versions PyPi Code repo Code Health

This 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-5121963

Self 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

$ pip install yamlordereddictloader

Loader usage

import yaml
import yamlordereddictloader

data = 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

import yaml
import yamlordereddictloader
from collections import OrderedDict

data = 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.

Metadata

Release files for yamlordereddictloader 0.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for yamlordereddictloader 0.4.2
File Size Uploaded
yamlordereddictloader-0.4.2.tar.gz 3.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for yamlordereddictloader 0.4.2
File Interpreter ABI Platform
yamlordereddictloader-0.4.2-py3-none-any.whl Python 3 none any Details

Total release size: 8.1 kB

Release files / yamlordereddictloader-0.4.2.tar.gz

Download URL yamlordereddictloader-0.4.2.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
36af2f6210fcff5da4fc4c12e1d815f973dceb41044e795e1f06115d634bca13
BLAKE2b-256 checksum
How to use checksums
2378f853b0db6d8f3ea0ae4c648e4504ba376d024c139ba1292a256ce6180dd0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / yamlordereddictloader-0.4.2-py3-none-any.whl

Download URL yamlordereddictloader-0.4.2-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc048adb67026786cd24119bd71241f35bc8b0fd37d24b415c37bbc8049f9cd7
BLAKE2b-256 checksum
How to use checksums
d3b664e84e26c52343dc48e9ffefd7d5e82b986f3bc2bd6da753420f41645718
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release history Release notifications | RSS feed

This release

0.4.2 This release

2 release files

0.4.0

1 release file

0.3.0

1 release file

0.2.2

1 release file

0.2.0

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page