@@ -31,6 +31,7 @@ attributes in the middle of function execution.
31
31
## Considered Options
32
32
1 . Usage of a ` ValidationMixin ` .
33
33
2 . Usage of a third-party library called ` pydantic ` .
34
+ 3 . Usage of a third-part library called ` marshmallow ` .
34
35
35
36
## Pros, Cons, and Considerations of the Options
36
37
@@ -173,10 +174,55 @@ This was concluded by performing the following steps:
173
174
functions with a name begging with `_validate` , the same way it' s done in the
174
175
`ValidationMixin` implementation in `in - toto` .
175
176
177
+ # ## Option 3: Usage of a third-part library called "marshmallow"
178
+
179
+ Here is how this option compares against our
180
+ (requirements)[# decision-drivers-and-requirements]:
181
+
182
+ | Number | Stance |
183
+ | ---------- - | ---------- - |
184
+ | 1 | It can validate only class attributes. |
185
+ | 2 | Yes, it allows that. |
186
+ | 3 | Likely slower than pydanitc (according to [pydantic](https:// pydantic- docs.helpmanual.io/ benchmarks/ )). |
187
+ | 4 | It adds 1 additional dependency. |
188
+ | 5 | Yes, it does support all of our python versions. |
189
+ | 6 | Yes, it does allow that. |
190
+ | 7 | Yes, it allows that through `validate()` function. |
191
+
192
+ Additional thoughts:
193
+
194
+ * Good, because it allows for strict type checks by marking the class attributes
195
+ (or Fields as they call them) as `strict` .
196
+
197
+ * Good, because it provides additional custom types (with their own built- in
198
+ validation) like `URL ` , `IPv4` , `IPv6` , etc.
199
+
200
+ * Bad, because it' s created with schemas in mind and a heavy focus on
201
+ serialization and deserialization. Most of the features are not related
202
+ to validation.
203
+
204
+ * Bad, because it adds one additional dependency - itself.
205
+ This was concluded by performing the following steps:
206
+ 1 . Creating a fresh virtual environment with python3.8.
207
+ 2 . Installing all dependencies in `requirements- dev.txt` from `tuf` .
208
+ 3 . Install `marshmallow` with `pip install marshmallow` .
209
+
210
+ * Bad, because they use their custom types even for types existing in the
211
+ standard `typing` module from python 3.6 onwards. This means that integrating
212
+ `marshmallow` would make up for a bigger diff compared to `pydantic` .
213
+ Additionally, because they define their types there could be problems specific
214
+ to their types and conversion from - to standard types as defined in the `typing`
215
+ python module.
216
+ This was the case when I researched `marshmallow` and had to use the
217
+ `marshmallow.fields.DateTime` class instead of the `datetime.datetime` object .
218
+
219
+
220
+
176
221
# # Links
177
222
* [in - toto ValidatorMixin](https:// github.com/ in - toto/ in - toto/ blob/ 74da7a / in_toto/ models/ common.py# L27-L40)
178
223
* [ValidatorMixing usage](https:// github.com/ in - toto/ in - toto/ blob/ 74da7a / in_toto/ models/ layout.py# L420-L438)
179
224
* [Pydantic documentation](https:// pydantic- docs.helpmanual.io/ )
225
+ * [Marshmallow documentation](https:// marshmallow.readthedocs.io/ )
180
226
181
227
# # Decision Outcome
182
228
0 commit comments