aleph.aleph module

Aleph X-Service wrapper.

This module allows you to query Aleph’s X-Services module (Aleph server is defined by ALEPH_URL in settings.py).

There are two levels of abstraction:

Lowlevel

You can use this functions to access Aleph:

searchInAleph(base, phrase, considerSimilar, field)
getDocumentIDs(aleph_search_result, [number_of_docs])
downloadMARCXML(doc_id, library)
downloadMARCOAI(doc_id, base)

Workflow

Aleph works in strange way, that he won’t allow you to access desired information directly.

You have to create search request by calling searchInAleph() first, which will return dictionary with few imporant informations about session.

This dictionary can be later used as parameter to function getDocumentIDs(), which will give you list of DocumentID named tuples.

Named tuples are used, because to access your document, you won’t need just document ID number, but also library ID string.

Depending on your system, there may be just only one accessible library, or mutiple ones, and then you will be glad, that you get both of this informations together.

DocumentID can be used as parameter to downloadMARCXML().

Lets look at some code:

ids = getDocumentIDs(searchInAleph("nkc", "test", False, "wrd"))
for id_num, library in ids:
    XML = downloadMARCXML(id_num, library)

    # processDocument(XML)

Highlevel

So far, there are only getter wrappers:

getISBNsIDs()
getAuthorsBooksIDs()
getPublishersBooksIDs()

And counting functions (they are one request to aleph faster than just counting results from getters):

getISBNCount()
getAuthorsBooksCount()
getPublishersBooksCount()

Other noteworthy properties

List of valid bases can be obtained by calling _getListOfBases(), which returns list of strings.

There is also defined exception tree - see AlephException docstring for details.

exception aleph.aleph.AlephException(message)[source]

Bases: exceptions.Exception

Exception tree:

- AlephException
  |- InvalidAlephBaseException
  |- InvalidAlephFieldException
  |- LibraryNotFoundException
  `- DocumentNotFoundException
class aleph.aleph.DocumentID[source]

Bases: aleph.aleph.DocumentID

This structure is used to store pointer to document in aleph.

id int

id of document

library str

can be different for each document

base str

default “nkc”, but really depends at what bases you have defined in your aleph

exception aleph.aleph.DocumentNotFoundException(message)[source]

Bases: aleph.aleph.AlephException

exception aleph.aleph.InvalidAlephBaseException(message)[source]

Bases: aleph.aleph.AlephException

exception aleph.aleph.InvalidAlephFieldException(message)[source]

Bases: aleph.aleph.AlephException

exception aleph.aleph.LibraryNotFoundException(message)[source]

Bases: aleph.aleph.AlephException

aleph.aleph.downloadMARCOAI(doc_id, base)[source]

Download MARC OAI document with given doc_id from given (logical) base.

Funny part is, that some documents can be obtained only with this function in their full text.

Parameters:
  • doc_id (str) – you will get this from getDocumentIDs()
  • base (str, optional) – Base from which you want to download Aleph document. This seems to be duplicite with searchInAleph() parameters, but it’s just somethin Aleph’s X-Services wants, so ..
Returns:

str – MARC XML unicode string.

Raises:
aleph.aleph.downloadMARCXML(doc_id, library)[source]

Download MARC XML document with given doc_id from given library.

Parameters:
Returns:

str – MARC XML unicode string.

Raises:
aleph.aleph.getAuthorsBooksCount(author, base='nkc')[source]

Get number of records in Aleph which match given author.

Parameters:
  • isbn (str) – Authors name/lastname in UTF
  • base (str, optional) – base on which will be search performed. Default settings.ALEPH_DEFAULT_BASE
Returns:

int – Number of matching documents in Aleph.

aleph.aleph.getAuthorsBooksIDs(author, base='nkc')[source]

Get list of DocumentID objects of documents with given author.

Parameters:
  • author (str) – Authors name/lastname in UTF
  • base (str, optional) – base on which will be search performed. Default settings.ALEPH_DEFAULT_BASE
Returns:

list – of DocumentID objects

aleph.aleph.getDocumentIDs(aleph_search_result, number_of_docs=-1)[source]

Get IDs, which can be used as parameters for other functions.

Parameters:
  • aleph_search_result (dict) – returned from searchInAleph()
  • number_of_docs (int, optional) – how many DocumentIDs from set given by aleph_search_result should be returned, default -1 for all of them.
Returns:

listDocumentID named tuples to given aleph_search_result.

Raises:

AlephException – if Aleph returns unknown format of data

Note

Returned DocumentID can be used as parameters to downloadMARCXML().

aleph.aleph.getISBNCount(isbn, base='nkc')[source]

Get number of records in Aleph which match given isbn.

Parameters:
  • isbn (str) – ISBN string
  • base (str, optional) – base on which will be search performed. Default settings.ALEPH_DEFAULT_BASE
Returns:

int – Number of matching documents in Aleph.

aleph.aleph.getISBNsIDs(isbn, base='nkc')[source]

Get list of DocumentID objects of documents with given isbn.

Parameters:
  • isbn (str) – ISBN string
  • base (str, optional) – base on which will be search performed. Default settings.ALEPH_DEFAULT_BASE
Returns:

list – of DocumentID objects

aleph.aleph.getPublishersBooksCount(publisher, base='nkc')[source]

Get number of records in Aleph which match given publisher.

Parameters:
  • isbn (str) – name of publisher which will be used to search Aleph
  • base (str, optional) – base on which will be search performed. Default settings.ALEPH_DEFAULT_BASE
Returns:

int – Number of matching documents in Aleph.

aleph.aleph.getPublishersBooksIDs(publisher, base='nkc')[source]

Get list of DocumentID objects of documents with given publisher.

Parameters:
  • publisher (str) – name of publisher which will be used to search Aleph
  • base (str, optional) – base on which will be search performed. Default settings.ALEPH_DEFAULT_BASE
Returns:

list – of DocumentID objects

aleph.aleph.searchInAleph(base, phrase, considerSimilar, field)[source]

Send request to the aleph search engine.

Request itself is pretty useless, but it can be later used as parameter for getAlephRecords(), which can fetch records from Aleph.

Parameters:
  • base (str) – which database you want to use
  • phrase (str) – what do you want to search
  • considerSimilar (bool) – fuzzy search, which is not working at all, so don’t use it
  • field (str) – where you want to look (see VALID_ALEPH_FIELDS)
Returns:

aleph_search_record, which is dictionary consisting from those fields

error (optional): present if there was some form of error
no_entries (int): number of entries that can be fetch from aleph
no_records (int): no idea what is this, but it is always >= than no_entries
set_number (int): important - something like ID of your request
session-id (str): used to count users for licensing purposes

Example

Returned dict:

{
 'session-id': 'YLI54HBQJESUTS678YYUNKEU4BNAUJDKA914GMF39J6K89VSCB',
 'set_number': 36520,
 'no_records': 1,
 'no_entries': 1
}
Raises:

Table Of Contents

This Page