Order nested YAML output using ruamel.yaml with custom key ordering
Project description
orderedYAML
A small Python package to recursively convert Python dicts/lists into ruamel.yaml-compatible, ordered YAML using CommentedMap. Preserves formatting, ordering, and supports custom key orders at any nesting depth.
Features
- Recursively reorders YAML dictionaries based on custom paths
- Outputs block-style YAML using
ruamel.yaml - Compatible with Python 3.7+
Installation
pip install orderedYAML
Usage
from core import OrderedYAML
data = {
"outerlist": {
"outeritems": [
{
"id": 1,
"name": "inner-1",
"inneritems": [
{"z": 3, "a": 1, "m": 2},
{"a": 4, "z": 5, "m": 6},
]
},
{
"id": 2,
"inneritems": [
{"m": 9, "z": 8, "a": 7}
],
"name": "inner-2"
}
]
}
}
ordering = {
"outerlist.outeritems[*]": ["name", "id", "inneritems"],
"outerlist.outeritems[].inneritems[*]": ["z", "m", "a", "q"]
}
oy = OrderedYAML(data, path_ordering=ordering)
print(oy.dumps())
Resulting in
outerlist:
outeritems:
- name: inner-1
id: 1
inneritems:
- z: 3
m: 2
a: 1
- z: 5
m: 6
a: 4
- name: inner-2
id: 2
inneritems:
- z: 8
m: 9
a: 7
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file orderedyaml-0.1.2.tar.gz.
File metadata
- Download URL: orderedyaml-0.1.2.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69b95cfe1ce72745b59b10362209056715770b9a230a2bb59b5f845470fdedd9
|
|
| MD5 |
e67fdd5822732926c406cd4f49f1b6f3
|
|
| BLAKE2b-256 |
0e3360b65833e15c1bb79026b8db09112fa2e2eca9dce2a54ca60f049781383c
|
File details
Details for the file orderedyaml-0.1.2-py3-none-any.whl.
File metadata
- Download URL: orderedyaml-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c448752293af326029c747c4d6fc3f55d04d4d2043b958bbc9616bc6de2651a
|
|
| MD5 |
2029fbcc5c2c8c8f24b638c2c764034c
|
|
| BLAKE2b-256 |
80698ee1160663161cf55748954e9fb81e439eb52849d32e4e7c1868d6952f79
|