Note

Note that each main class and module has a help() method, accessible via <class/module>.help(). These help() methods are simply docstring printers and hinters, so they will not be touched on in this documentation.

« Back (storage.py) Next » (edit.py)
   

load.py

This module houses the Load class, a helper class that loads JSON objects stored with Storage.store() back into Storage objects.

Structure of the Module

Tip

Click on a class or method below to go straight to its documentation!

Storage.Load

Methods

Storage.Load.by_key()

@classmethod
def by_key(cls,
           file_path: str,
           key: Any,
           raw: bool=False
          ) -> Storage | None:

Load a json file and find the key to extract a single key-multivalue pair and its values.

Arguments
Symbol Type Hint Default Description
file_path str Required Path to JSON file.
key Any Required Top-level key to search for (strings recommended).
raw bool False If False attempt to decode encoded values; if True return raw stored values.
Output
Example
s = Storage.Load.by_key("db.json", "users")
print(repr(s))

Storage.Load.by_index()

@classmethod
def by_index(cls,
             file_path: str,
             index: int,
             raw: bool=False
            ) -> Storage | None:

Load a json file and find the index at which to extract a single key-multivalue pair and its values.

Do note that this method bases the start index at 0.

Arguments
Symbol Type Hint Default Description
file_path str Required Path to JSON file.
index int Required 0-based index of top-level key to return.
raw bool False If False attempt to decode encoded values; if True return raw stored values.
Returns
Example

Storage.Load.keys()

@classmethod
def keys(cls,
         file_path: str
        ) -> list[str] | None:

Load a json file and returns the keys of that file.

Arguments
Symbol Type Hint Default Description
file_path str Required Path to JSON file.
Returns
Example

Storage.Load.values()

@classmethod
def values(cls,
           file_path: str,
           key: Any,
           keys: bool=False,
           raw: bool=True
          ) -> list[str] | None:

Loads a json file and returns the values under the inputed key.

Unlike other loading methods, this one returns the raw values by default.

Keys can also be returned as a key-value pair if keys=True.

Arguments
Symbol Type Hint Default Description
file_path str Required Path to JSON file.
key Any Required Top-level key to fetch values for.
keys bool False If True, returns ["prop: value", ...] strings; otherwise returns list of values.
raw bool True If True, return raw stored values (no decode). If False, attempt to decode encoded ints.
Returns
Example

Other Info