+ """A class that stores its state in a JSON format file.
+
+ Example usage::
+
+ import persistent
+
+ @persistent.persistent_autoloaded_singleton()
+ class MyClass(persistent.JsonFileBasedPersistent):
+ def __init__(self, data: Optional[dict[str, Any]]):
+ # load already deserialized the JSON data for you; it's
+ # a "cooked" JSON dict of string -> values, lists, dicts,
+ # etc...
+ if data:
+ #initialize youself from data...
+ else:
+ # if desired, initialize an empty state object
+ # when json_data isn't provided.
+
+ @staticmethod
+ @overrides
+ def get_filename() -> str:
+ return "/path/to/where/you/want/to/save/data.json"
+
+ @staticmethod
+ @overrides
+ def should_we_save_data(filename: str) -> bool:
+ return true_if_we_should_save_the_data_this_time()
+
+ @staticmethod
+ @overrides
+ def should_we_load_data(filename: str) -> bool:
+ return persistent.was_file_written_within_n_seconds(whatever)
+
+ # Persistent will handle the plumbing to instantiate your
+ # class from its persisted state iff the
+ # :meth:`should_we_load_data` says it's ok to. It will also
+ # persist the current in memory state to disk at program exit
+ # iff the :meth:`should_we_save_data methods` says to.
+ c = MyClass()
+ """
+