s2.db

Warning

This module is deprecated in favor of s2.store.

PyS2 allows you to store and retrieve S2Paper and S2Author objects via arbitrary MutableMapping classes. For an example, see Working Locally with s2.store.

JsonS2PaperDB

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

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

Note

Types are enforced, so keys must be valid PaperIds and values must be instances of S2Paper.

Parameters
  • json_dir (str or Path) –

    Directory where papers 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:

    pdb = JsonS2PaperDB("db")
    paper = s2.api.get_paper(k)
    pdb[k] = paper
    

    will first create a directory db, then a file db/{k}.json containing the S2Paper 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 paperId field of the S2Paper object (if it exists; for handling unknown references without a paperId value, see Saving Objects without S2 Identifiers).

paperIds

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

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