Types that support validation in Pydantic.

Pydantic recognizes magic method __get_validators__ to receive additional validators, that can be used, i.e., for custom serialization and deserialization. We implement several custom types here to tune behavior of our models.

See Pydantic documentation for more information about implementing new types.

Module Contents#



Pydantic-compatible version of numpy.ndarray.


Pydantic-compatible version of networkx.Graph.

class NDArray(shape, dtype=float, buffer=None, offset=0, strides=None, order=None)[source]#

Bases: numpy.ndarray

Pydantic-compatible version of numpy.ndarray.

Serialization is implemented using custom methods to_dict() and from_dict(). Data array is encoded in Base64.

to_dict() dict[str, Any][source]#

Convert the array to JSON-compatible dictionary.

classmethod from_dict(serialized: collections.abc.Mapping[str, Any]) NDArray[source]#

Construct an instance from a dictionary generated by :meth`to_dict`.


serialized – Dictionary that has "data", "shape" and "dtype" keys.”, where data is a base64-encoded bytes array, shape is a tuple and dtype is a string representation of a Numpy data type.

classmethod validate(v: Any) NDArray[source]#

Validate the data and cast from all known representations.

class Graph(incoming_graph_data=None, **attr)[source]#

Bases: networkx.Graph

Pydantic-compatible version of networkx.Graph.

classmethod validate(v: Any) Graph[source]#

Validate the data and cast from all known representations.