File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,6 +14,13 @@ and this project adheres to **[Semantic Versioning](https://semver.org/spec/v2.0
1414
1515---
1616
17+ ## [ 0.9.10] - 2025-10-26
18+
19+ ### Changed
20+ - add yaml_utils
21+
22+ ---
23+
1724## [ 0.9.9] - 2025-10-26
1825
1926### Changed
@@ -58,7 +65,8 @@ and this project adheres to **[Semantic Versioning](https://semver.org/spec/v2.0
5865 Tag the repository with ` vX.Y.Z ` to publish a release.
5966- Documentation and badges are updated per tag and aliased to ** latest** .
6067
61- [ Unreleased ] : https://github.com/civic-interconnect/civic-transparency-py-sdk/compare/v0.9.9...HEAD
68+ [ Unreleased ] : https://github.com/civic-interconnect/civic-transparency-py-sdk/compare/v0.9.10...HEAD
69+ [ 0.9.10 ] : https://github.com/civic-interconnect/civic-transparency-py-sdk/releases/tag/v0.9.10
6270[ 0.9.9 ] : https://github.com/civic-interconnect/civic-transparency-py-sdk/releases/tag/v0.9.9
6371[ 0.9.8 ] : https://github.com/civic-interconnect/civic-transparency-py-sdk/releases/tag/v0.9.8
6472[ 0.9.7 ] : https://github.com/civic-interconnect/civic-transparency-py-sdk/releases/tag/v0.9.7
Original file line number Diff line number Diff line change 1+ """Lightweight helpers for reading and writing YAML files.
2+
3+ File: yaml_utils.py
4+ """
5+
6+ from pathlib import Path
7+ from typing import Any
8+
9+ import yaml
10+
11+ __all__ = ["write_yaml" , "read_yaml" ]
12+
13+
14+ def write_yaml (data : dict [str , Any ], path : str | Path ) -> Path :
15+ """Write a dictionary to a YAML file.
16+
17+ Args:
18+ data (dict): Data to write.
19+ path (str | Path): File path to write to.
20+
21+ Returns:
22+ Path: The path the file was written to.
23+ """
24+ path = Path (path )
25+ path .parent .mkdir (parents = True , exist_ok = True )
26+ with path .open ("w" , encoding = "utf-8" ) as f :
27+ yaml .dump (data , f , sort_keys = False )
28+ return path
29+
30+
31+ def read_yaml (path : str | Path ) -> dict [str , Any ]:
32+ """Read and parse a YAML file into a dictionary.
33+
34+ Args:
35+ path (str | Path): YAML file path.
36+
37+ Returns:
38+ dict: Parsed YAML data.
39+ """
40+ path = Path (path )
41+ with path .open ("r" , encoding = "utf-8" ) as f :
42+ return yaml .safe_load (f )
Original file line number Diff line number Diff line change 1+ from pathlib import Path
2+ import tempfile
3+
4+ from civic_lib_core .yaml_utils import read_yaml , write_yaml
5+
6+
7+ def test_roundtrip_yaml ():
8+ data = {"a" : 1 , "b" : {"c" : 2 }}
9+ tmp = Path (tempfile .gettempdir ()) / "test.yaml"
10+ write_yaml (data , tmp )
11+ assert read_yaml (tmp ) == data
You can’t perform that action at this time.
0 commit comments