You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PyYaml is a great library. However it is a bit hard for anyone to add the yaml capability to their classes. Its `YamlObject` helper class is a first step but it has two drawbacks:
8
+
8
9
* one has to master PyYaml Loader/Dumper internal features to understand what they are doing
9
10
* there is a mandatory metaclass, which can prevent wide adoption (multiple inheritance with metaclasses...)
10
11
11
-
`yamlable` provides a very easy way for you to leverage PyYaml without suffering the complexity: simply inherit from `YamlAble`, decorate with `@yaml_info`, implement the abstract methods to write to / load from a dictionary, and you're set!
12
+
`yamlable` provides a very easy way for you to leverage PyYaml without seeing the complexity: simply inherit from `YamlAble`, decorate with `@yaml_info`, implement the abstract methods to write to / load from a dictionary, and you're set!
12
13
13
-
In addition `yamlable` provides
14
-
* a way to creade Yaml codecs for several object types at the same time (`YamlCodec`).
15
-
* an alternative to `YamlAble` that relies strictly on `YamlObject`: `YamlObject2`
14
+
In addition `yamlable` provides a way to creade Yaml codecs for several object types at the same time (`YamlCodec`) (see Usage page)
16
15
17
16
18
17
## Installing
@@ -24,6 +23,7 @@ In addition `yamlable` provides
24
23
## Usage
25
24
26
25
Let's make a class yaml-able: we have to
26
+
27
27
- inherit from `YamlAble`
28
28
- decorate it with the `@yaml_info` annotation to declare the associated yaml tag
29
29
- implement `from_yaml_dict` (class method called during decoding) and `to_yaml_dict` (instance method called during encoding)
@@ -89,14 +89,17 @@ a: 1
89
89
b: hello
90
90
```
91
91
92
+
For more general cases where your object is embedded in a more complex structure for example, you can of course call pyyaml `dump`/`load` functions, it will work as expected.
93
+
94
+
92
95
See [Usage](./usage) for other possibilities of `yamlable`.
93
96
94
97
95
98
## Main features / benefits
96
99
97
100
* Add yaml-ability to any class easily through inheritance without metaclass (as opposed to `YamlObject`) and without knowledge of internal PyYaml loader/dumper logic.
98
101
* Write codecs to support several types at a time with `YamlCodec`
99
-
102
+
* If you absolutely wish to use PyYaml's `YamlObject` for some reason, you can use `YamlObject2` as an alternative to `YamlAble`. But it comes with the metaclass, like `YamlObject`.
0 commit comments