aleph package¶
Query workflow¶
AQMP is handled by edeposit.amqp
module, this package provides just datastructures and
reactToAMQPMessage()
function, which is used in daemon to translate
highlevel requests to lowlevel queries to Aleph’s webapi.
AMQP query¶
To query Aleph thru AMQP, run edeposit_amqp_alephdaemon
(from
edeposit.amqp
package) and create one of the Queries -
ISBNQuery
for example and put it into SearchRequest
wrapper
and send the message to the Aleph’s exchange:
request = SearchRequest(
ISBNQuery("80-251-0225-4")
)
amqp.send( # you can use pika library to send data to AMQP queue
message = serialize(request),
properties = "..",
exchange = "ALEPH'S_EXCHANGE"
)
and you will get back AMQP message with SearchResult
.
Poznámka
You don’t have to import all structures from datastructures
, they
should be automatically imported and made global in __init__.py
.
Count requests¶
If you want to just get count of how many items is there in Aleph, just wrap
the ISBNQuery
with CountRequest
class:
isbnq = ISBNQuery("80-251-0225-4")
request = CountRequest(isbnq)
# rest is same..
and you will get back CountResult
.
Poznámka
You should always use CountRequest
instead of just calling
len()
to SearchResult.records
- it doesn’t put that
much load to Aleph. Also Aleph is restricted to 150 requests per second.
Direct queries¶
As I said, this module provides only direct access to Aleph, AMQP communication
is handled in edeposit.amqp
.
If you want to access module directly, you can use reactToAMQPMessage()
wrapper, or query aleph
submodule directly.
reactToAMQPMessage()
is preferred, because in that case, you don’t have
to deal with Aleph lowlevel API, which can be little bit annoying.
Diagrams¶
Here is ASCII flow diagram for you:
ISBNQuery ----. ,--> CountResult
AuthorQuery ----| | `- num_of_records
PublisherQuery ----| |
TitleQuery ----| ExportRequest |--> SearchResult
GenericQuery ----| ISBNValidationRequest | `- AlephRecord
DocumentQuery ----| | |
ICZQuery ----| | |--> ISBNValidationResult
| | | - ISBN
V | |
Count/Search/ExportRequest | |--> ExportResult
| | |
| | |
| | |
V | |
serialize()<----------' deserialize()
| ^
V Client |
AMQPMessage ------> AMQP -------> AMQPMessage
| ^
V |
| ^
V |
| ^
V |
AMQPMessage <------ AMQP <-------- AMQPMessage
| Service ^
| |
V |
reactToAMQPMessage() ............... magic_happens()
and here is (pseudo) UML:
Neat, isn’t it?
API¶
-
class
aleph.
GenericQuery
[zdroj]¶ Nadtřídy:
aleph.GenericQuery
,aleph._QueryTemplate
Used for generic queries to Aleph.
Parametry: - base (str) – Which base in Aleph will be queried. This depends on
settings of your server. See
aleph.getListOfBases()
for details. - phrase (str) – What are you looking for.
- considerSimilar (bool) – Don’t use this, it usually doesn’t work.
- field (str) – Which field you want to use for search.
See
aleph.VALID_ALEPH_FIELDS
for list of valid bases.
For details of base/phrase/.. parameters, see
aleph.searchInAleph()
. All parameters also serves as properties.This is used mainly if you want to search by your own parameters and don’t want to use prepared wrappers (
AuthorQuery
/ISBNQuery
/..).- base (str) – Which base in Aleph will be queried. This depends on
settings of your server. See
-
class
aleph.
DocumentQuery
[zdroj]¶ Nadtřídy:
aleph.DocumentQuery
Query Aleph when you know the Document ID.
Parametry: - doc_id (str) – ID number as string.
- library (str, default settings.DEFAULT_LIBRARY) – Library.
-
getSearchResult
()[zdroj]¶ Vrací: SearchResult
document with given doc_id.Typ návratové hodnoty: object Raises: aleph.DocumentNotFoundException
– When document is not found.
-
class
aleph.
ISBNQuery
[zdroj]¶ Nadtřídy:
aleph.ISBNQuery
,aleph._QueryTemplate
Used to query Aleph to get books by ISBN.
Parametry: - ISBN (str) – ISBN 10/13.
- base (str, optional) – If not set,
settings.ALEPH_DEFAULT_BASE
is used.
Poznámka
ISBN is not unique, so you can get back lot of books with same ISBN. Some books also have two or more ISBNs.
-
class
aleph.
AuthorQuery
[zdroj]¶ Nadtřídy:
aleph.AuthorQuery
,aleph._QueryTemplate
Used to query Aleph to get books by Author.
Parametry: - author (str) – Author’s name/lastname in UTF-8.
- base (str, optional) – If not set,
settings.ALEPH_DEFAULT_BASE
is used.
-
class
aleph.
PublisherQuery
[zdroj]¶ Nadtřídy:
aleph.PublisherQuery
,aleph._QueryTemplate
Used to query Aleph to get books by Publisher.
Parametry: - publisher (str) – Publisher’s name in UTF-8.
- base (str, optional) – If not set,
settings.ALEPH_DEFAULT_BASE
is used.
-
class
aleph.
TitleQuery
[zdroj]¶ Nadtřídy:
aleph._QueryTemplate
,aleph.TitleQuery
Used to query Aleph to get books by book’s title/name.
Parametry: - title (str) – Book’s title in UTF-8.
- base (str, optional) – If not set,
settings.ALEPH_DEFAULT_BASE
is used.
-
class
aleph.
ICZQuery
[zdroj]¶ Nadtřídy:
aleph._QueryTemplate
,aleph.ICZQuery
Used to query Aleph to get books by record’s identification number icz.
Parametry: - icz (str) – Identification number (
nkc20150003029
for example). - base (str, optional) – If not set,
settings.ALEPH_DEFAULT_BASE
is used.
- icz (str) – Identification number (
-
aleph.
reactToAMQPMessage
(req, send_back)[zdroj]¶ React to given (AMQP) message.
This function is used by
edeposit.amqp.alephdaemon
. It works as highlevel wrapper for whole module.Example
>>> import aleph
>>> request = aleph.SearchRequest( ... aleph.ISBNQuery("80-251-0225-4") ... ) >>> request SearchRequest(query=ISBNQuery(ISBN='80-251-0225-4', base='nkc'))
>>> response = aleph.reactToAMQPMessage(request, None)
>>> response # formated by hand for purposes of example SearchResult( records=[ AlephRecord( base='nkc', library='NKC01', docNumber=1492461, xml='HERE IS WHOLE MARC OAI RECORD', epublication=EPublication( ISBN=['80-251-0225-4'], nazev='Umění programování v UNIXu /', podnazev='', vazba='(brož.) :', cena='Kč 590,00', castDil='', nazevCasti='', nakladatelVydavatel='Computer Press,', datumVydani='2004', poradiVydani='1. vyd.', zpracovatelZaznamu='BOA001', format='23 cm', url='', mistoVydani='Brno :', ISBNSouboruPublikaci=[], autori=[ Author( firstName='Eric S.', lastName='Raymond', title='' ) ], originaly=[ 'Art of UNIX programming' ], internal_url='' ) ) ] )
Parametry: - req (Request class) – Any of the Request class from
aleph.datastructures.requests
. - send_back (fn reference) – Reference to function for responding. This is useful for progress monitoring for example. Function takes one parameter, which may be response structure/namedtuple, or string or whatever would be normally returned.
Vrací: Result of search in Aleph. See
aleph.datastructures.results
submodule.Typ návratové hodnoty: Result class
Raises: ValueError
– If bad type of req structure is given.- req (Request class) – Any of the Request class from