polymerist.genutils.fileutils.jsonio ==================================== .. py:module:: polymerist.genutils.fileutils.jsonio .. autoapi-nested-parse:: Utilities for extending the Python-JSON interface Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/polymerist/genutils/fileutils/jsonio/jsonify/index /autoapi/polymerist/genutils/fileutils/jsonio/serialize/index /autoapi/polymerist/genutils/fileutils/jsonio/update/index Attributes ---------- .. autoapisummary:: polymerist.genutils.fileutils.jsonio.JSONSerializable Classes ------- .. autoapisummary:: polymerist.genutils.fileutils.jsonio.JSONifiable polymerist.genutils.fileutils.jsonio.TypeSerializer polymerist.genutils.fileutils.jsonio.MultiTypeSerializer polymerist.genutils.fileutils.jsonio.PathSerializer polymerist.genutils.fileutils.jsonio.QuantitySerializer polymerist.genutils.fileutils.jsonio.JSONDict Functions --------- .. autoapisummary:: polymerist.genutils.fileutils.jsonio.make_jsonifiable polymerist.genutils.fileutils.jsonio.append_to_json Package Contents ---------------- .. py:class:: JSONifiable For type-hinting classes which are jsonifiable .. py:function:: make_jsonifiable(cls: Optional[C] = None, type_serializer: Optional[Union[polymerist.genutils.fileutils.jsonio.serialize.TypeSerializer, polymerist.genutils.fileutils.jsonio.serialize.MultiTypeSerializer]] = None) -> C Modify a dataclass to make its attributes writeable-to and readable-from JSON files Can optionally specify additional TypeSerializers to support objects with attributes whose types are, by default, not JSON-serializable .. py:data:: JSONSerializable .. py:class:: TypeSerializer Bases: :py:obj:`abc.ABC` Interface for defining how types which are not JSON serializable by default should be encoded and decoded .. py:attribute:: python_type :type: ClassVar[Type[T]] .. py:method:: encode(python_obj: T) -> JSONSerializable :staticmethod: :abstractmethod: .. py:method:: decode(json_obj: JSONSerializable) -> T :staticmethod: :abstractmethod: .. py:method:: encoder_default(python_obj: Any) -> JSONSerializable :classmethod: Augmented Encoder for encoding registered objects along with type info for decoding .. py:method:: decoder_hook(json_dict: dict[JSONSerializable, JSONSerializable]) -> Union[dict, T] :classmethod: .. py:class:: MultiTypeSerializer(*type_sers: tuple[Type[TypeSerializer]]) For dynamically merging multiple TypeSerializer encoders and decoders .. py:property:: type_sers :type: list[Type[TypeSerializer]] Read-only wrapper for the internal registry of TypeSerializers .. py:method:: add_type_serializer(obj: Union[TypeSerializer, MultiTypeSerializer]) -> None For type, instance, and uniqueness checking of Type .. py:method:: encoder_default(python_obj: Any) -> JSONSerializable .. py:method:: decoder_hook(json_dict: dict[JSONSerializable, JSONSerializable]) -> Any .. py:class:: PathSerializer Bases: :py:obj:`TypeSerializer` For JSON-serializing OpenMM Quantities .. py:method:: encode(python_obj: pathlib.Path) -> str :staticmethod: Stringify path object .. py:method:: decode(json_obj: str) -> pathlib.Path :staticmethod: Resolve string into system Path .. py:class:: QuantitySerializer Bases: :py:obj:`TypeSerializer` For JSON-serializing OpenMM Quantities .. py:method:: encode(python_obj: openmm.unit.Quantity) -> dict[str, Union[str, float]] :staticmethod: Separate openmm.unit.Quantity's value and units to serialize as a single dict .. py:method:: decode(json_obj: dict[str, Union[str, float]]) -> openmm.unit.Quantity :staticmethod: Unpack a value-unit string dict back into a usable openmm.unit.Quantity .. py:function:: append_to_json(json_path: pathlib.Path, **kwargs) -> None Add an entry to an existing JSON file .. py:class:: JSONDict(json_path: pathlib.Path, *args, **kwargs) Bases: :py:obj:`dict` Dict subclass which also updates an underlying JSON file - effectively and on-disc dict !NOTE! - JSON doesn't support non-string keys, so all keys given will be stringified - plan accordingly! .. py:attribute:: json_path :type: pathlib.Path