Registry / devops / yamlable

yamlable

JSON →
library1.1.1pypypi✓ verified 83d ago

A thin wrapper around PyYAML that provides automatic serialization and deserialization of Python objects to/from YAML. Version 1.1.1 is current. Release cadence is low, with occasional maintenance updates.

pip install yamlable
INSTALL
IMPORT
SIG · YAMLABLE
Y
yamlable
devopspythonv1.1.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

YamlAble
from yamlable import YamlAble
The base class for making objects YAML-serializable.
yaml_info
from yamlable import yaml_info
Decorator for marking class YAML tag info.

Defines a YAML-serializable class with custom tag, then serializes and deserializes.

from yamlable import YamlAble, yaml_info @yaml_info(yaml_tag='!person') class Person(YamlAble): def __init__(self, name, age): self.name = name self.age = age p = Person('Alice', 30) yaml_str = YamlAble.to_yaml(p) print(yaml_str) # Output: # !person {age: 30, name: Alice} obj = YamlAble.from_yaml(yaml_str) assert isinstance(obj, Person) print(obj.name) # Alice
Debug
Known issues
gotchayamlable only works with class instances (not dicts or primitives). For dicts, use PyYAML directly.
fix
Use PyYAML's `yaml.dump` for plain dicts.
affects: all
gotchaThe `yaml_tag` must be unique across all classes; duplicate tags cause ambiguous loading.
fix
Use unique tag names per class.
affects: all
breakingVersion 1.0.0 changed the import base class from `YamlObj` to `YamlAble`. Old code using `YamlObj` breaks.
fix
Replace `from yamlable import YamlObj` with `from yamlable import YamlAble` and rename usage.
affects: <1.0.0
Errors
Common errors & fixes
TypeError: Cannot dump type <class '__main__.MyClass'>
The class does not inherit from YamlAble or lacks @yaml_info decorator.
fix
Inherit from YamlAble and decorate with @yaml_info(yaml_tag='!mytag').
yaml.constructor.ConstructorError: could not determine a constructor for the tag '!mytag'
The tag is used in YAML but no corresponding class with that tag has been registered (or the class wasn't imported before loading).
fix
Ensure the class with that @yaml_info tag is imported before calling `YamlAble.from_yaml`.
AttributeError: 'str' object has no attribute 'name'
Trying to use YamlAble.from_yaml on a plain YAML string that doesn't contain an object with the expected tag (e.g., a scalar or mapping without tag). It returns a dict/str instead of the expected class instance.
fix
Annotate your YAML with appropriate tags or use `yaml.load` with `Loader=yaml.SafeLoader` for non-tagged data.
Upgrade
Version history
1.1.1latest on PyPI · released Jul 6, 2022
Audit
Dependencies
PyYAMLrequiredRequired for YAML parsing and emitting.
Agent activity
20 hits · last 30 days
node
16
Amazon
1
Resources
yamlable — pip install yamlable · libregistry