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 filedb/{k}.jsoncontaining 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
authorIdfield of theS2Authorobject (if it exists; for handling unknown authors without anauthorIdvalue, 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