Storage module¶
Note
To access the classes in this module, you need to extend the lib by importing biblib.storage
.
This module contains basic reader and writer classes, with the interfaces implemented as abstract base classes.
They will handle ids (cite keys), entries and dictonaries ({‘cite key’: entry}) as input and will return an entry or a dictonary ({‘cite key’: entry}).
The following classes are provided:
- Abstract Base Classes
- String
- DOI
- ISBN
- SQLite
>>> from biblib.storage import FileStorage, DoiReadStorage
>>> # init storages
>>> doiStorage = DoiReadStorage()
>>> storage = FileStorage('/path/to/file.bib')
>>> # read entries from file
>>> entries = storage.readEntries()
{'CiteKey': <biblib._entry.Entry object at 0x808184390>}
>>> # fetch entry from doi and add it to the file storage
>>> entry = doiStorage.readEntry('10.1103/physrevlett.108.105901')
>>> storage.createEntry(entry, 'OtherCiteKey')
>>> entries = storage.readEntries()
{'CiteKey': <biblib._entry.Entry object at 0x808184390>, 'OtherCiteKey': <biblib._entry.Entry object at 0x8081eef90>}
Abstract Base Classes¶
-
class
biblib.storage.
ReadStorage
(src)[source]¶ AbstractBaseClass ReadStorage
Parameters: src (str) – data source to act on
-
class
biblib.storage.
WriteStorage
(src)[source]¶ AbstractBaseClass WriteStorage
Parameters: src (str) – data source to act on -
createEntry
(entry, id=None)[source]¶ Add Entry to storage source
Parameters: - entry (
Entry
) – Entry to store - id (str) – id to store entry with
- entry (
-
updateEntry
(entry, id=None)[source]¶ update Entry in storage source
Parameters: - entry (
Entry
) – Entry to store - id (str) – id to store entry with
- entry (
-
String Storage¶
-
class
biblib.storage.
StringReadStorage
(bibStr)[source]¶ Bases:
biblib.storage.ReadStorage
ReadStorage that stores the data in a string.
Parameters: bibStr (str) – BibTex string -
classmethod
entriesFromString
(bibStr)[source]¶ Transform bibtex string into a dictonary of Entries.
Parameters: bibStr (unicode) – bibtex string Returns: dictonary of Entries Return type: dict of Entries
-
classmethod
-
class
biblib.storage.
StringStorage
(src, encoding='ascii')[source]¶ Bases:
biblib.storage.StringReadStorage
,biblib.storage.WriteStorage
ReadWriteStorage that stores the data in a string.
Parameters: - bibStr (str) – BibTex string
- encoding (str) – string encoding
File Storage¶
-
class
biblib.storage.
FileReadStorage
(file)[source]¶ Bases:
biblib.storage.StringReadStorage
ReadStorage that reads the data from a file.
Parameters: file (str) – path to file
-
class
biblib.storage.
FileStorage
(file, encoding='ascii')[source]¶ Bases:
biblib.storage.FileReadStorage
,biblib.storage.StringStorage
ReadWriteStorage that stores the data in a file.
Parameters: - file (str) – path to file
- encoding (str) – string encoding
Doi Storage¶
-
class
biblib.storage.
DoiReadStorage
[source]¶ Bases:
biblib.storage.ReadStorage
ReadStorage that reads the data from the doi database.
ISBN Storage¶
-
class
biblib.storage.
IsbnReadStorage
[source]¶ Bases:
biblib.storage.ReadStorage
ReadStorage that reads the data for a given ISBN.
Sqlite3 Storage¶
-
class
biblib.storage.
SqliteStorage
(src)[source]¶ Bases:
biblib.storage.ReadStorage
,biblib.storage.WriteStorage
ReadWriteStorage that stores the data in SQLite3 database
Parameters: file (str) – path to db file