aleph package

Contents

aleph package

Module content

Query workflow

To query Aleph, just create one of the Queries - ISBNQuery for example and put it into aleph.datastructures.requests.SearchRequest wrapper. Then encode it by calling serialize() and send the message to the Aleph’s exchange:

isbnq = ISBNQuery("80-251-0225-4")
request = SearchRequest(isbnq)

amqp.send(
    message    = serialize(request),
    properties = "..",
    exchange   = "ALEPH'S_EXCHANGE"
)

and you will get back AMQP message, and after decoding with fromAMQPMessage() also SearchResult.

Note

You don’t have to import all structures from datastructures, they should be automatically imported and made global in __init__.py.

If you want to just get count of how many items is there in Aleph, just wrap the ISBNQuery with CountRequest:

isbnq = ISBNQuery("80-251-0225-4")
request = CountRequest(isbnq)

# rest is same..

and you will get back (after decoding) aleph.datastructures.results.CountResult.

Note

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.

Here is ASCII flow diagram for you:

ISBNQuery      ----.                                 ,--> CountResult
AuthorQuery    ----|                                 |       `- num_of_records
PublisherQuery ----|                                 |
GenericQuery   ----|      ISBNValidationRequest      |--> SearchResult
                   |                |                |       `- AlephRecord
                   V                |                |
      Count/Search/ExportRequest    |                |--> ISBNValidationResult
                   |                |                |        - ISBN
                   V                |                |
                   |                |                |--> ExportResult
                   V                |                |
              serialize()<----------'           deserialize()
                   |                                 ^
                   V             Client              |
              AMQPMessage ------> AMQP -------> AMQPMessage
                                 |    ^
                                 V    |
                                 |    ^
                                 V    |
                                 |    ^
                                 V    |
              AMQPMessage <------ AMQP <-------- AMQPMessage
                   |             Service              ^
                   |                                  |
                   V                                  |
          reactToAMQPMessage() ............... magic_happens()

Neat, isn’t it?

class aleph.AuthorQuery[source]

Bases: aleph.AuthorQuery, aleph._QueryTemplate

Query Aleph to get books by Author.

Parameters:
  • author (str) – Author’s name/lastname in UTF
  • base (str, optional) – if not set, settings.ALEPH_DEFAULT_BASE is used
class aleph.GenericQuery[source]

Bases: aleph.GenericQuery, aleph._QueryTemplate

Used for generic queries to aleph.

Parameters:
  • base (str)
  • phrase (str)
  • considerSimilar (bool)
  • field (str)

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/..).

class aleph.ISBNQuery[source]

Bases: aleph.ISBNQuery, aleph._QueryTemplate

Query Aleph to get books by ISBN.

Parameters:
  • ISBN (str)
  • base (str, optional) – if not set, settings.ALEPH_DEFAULT_BASE is used

Note

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.PublisherQuery[source]

Bases: aleph.PublisherQuery, aleph._QueryTemplate

Query Aleph to get books by Publisher.

Parameters:
  • publisher (str) – publisher’s name in UTF
  • base (str, optional) – if not set, settings.ALEPH_DEFAULT_BASE is used
aleph.deserialize(data)[source]

Deserialize classes from JSON data.

Parameters:data (str) – python data serialized to JSON
Returns:any – any python typ (make sure you have namedtuples imported)
aleph.reactToAMQPMessage(message, response_callback, UUID)[source]

React to given (AMQP) message. Return data thru given callback function.

Parameters:
  • message (str or Request class) – message encoded in JSON by serialize() or any of the Request class from aleph.datastructures.requests
  • response_callback (func) – function has to take two parameters - message’s body (serialized response class) and UUID
  • UUID (str) – unique ID of received message

Note

Function take care of sending the response over AMQP, or whatever you use.

Returns:result of response_callback() call.
Raises:ValueError – if bad type of message structure is given.
aleph.serialize(data)[source]

Serialize class hierarchy into JSON.

Parameters:data (any) – any python type serializable to JSON, with added support of namedtuples
Returns:unicode – JSON string

Contents