JsonS2AuthorDB

class s2.db.json.JsonS2AuthorDB(json_dir, enforce_id=True)

Dict-like interface to store S2Authors as jsons and retrieve as S2Authors

Note

Types are enforced, so keys must be valid AuthorIds and values must be instances of S2Author.

Parameters
  • json_dir (str or Path) –

    Directory where authors are saved as jsons. If directory does not exist, it will be created and populated with jsons as values are set in the object. For example:

    adb = JsonS2AuthorDB("db")
    author = s2.api.get_author(k)
    adb[k] = author
    

    will first create a directory db, then a file db/{k}.json containing the class:.S2Author that was passed, in a json-serialized format.

    Similarly, removing items from the object (e.g. pdb.pop(k)) will delete the corresponding json file.

  • enforce_id (bool, optional) – Enforce that a key be equal to the authorId field of the S2Author object (if it exists; for handling unknown authors without an authorId value, see Saving Objects without S2 Identifiers).

authorIds

In-memory lookup of existing keys, updated whenever a key is added or removed. Will likely be updated to something less scrappy.

Type

set of str