pyiv_common.serde
YAML SerDe for pyiv, backed by PyYAML.
This module provides YAMLSerDe, a pyiv.serde.SerDe implementation
that uses PyYAML. Infrastructure (SerDe, chain handlers) stays in core.
What Problem Does This Solve?
YAML is a common config and payload format, but PyYAML is not in the Python standard library. Core pyiv must not import it. This extra ships the YAML codec without changing the SerDe API.
Real-World Use Cases: - Load YAML config documents through the injector - Encode/decode YAML payloads on an ENCODING chain
Example
>>> from pyiv_common.serde import YAMLSerDe
>>> serde = YAMLSerDe()
>>> serde.handler_type
'yaml'
>>> data = serde.serialize({"key": "value"})
>>> serde.deserialize(data)["key"]
'value'
Classes
YAML encoding SerDe using PyYAML. |
- class pyiv_common.serde.YAMLSerDe[source]
Bases:
SerDeYAML encoding SerDe using PyYAML.
Install with
pip install pyiv-common. Register on the ENCODING chain like any otherSerDe.Example
>>> from pyiv import ChainType, Config, get_injector >>> from pyiv_common.serde import YAMLSerDe >>> class MyConfig(Config): ... def configure(self): ... self.register_chain_handler(ChainType.ENCODING, "yaml", YAMLSerDe) >>> injector = get_injector(MyConfig) >>> serde = injector.inject_chain_handler(ChainType.ENCODING, "yaml") >>> serde.deserialize(serde.serialize({"a": 1})) {'a': 1}