My favorites | Sign in
Project Logo
                
Search
for
Updated Mar 24, 2008 by bziclix
Batchables  
pysmug's batchable operations can dramatically improve performance.

Introduction

Some operations, such as getting all the EXIF info for every photo in an album can be very time consuming because the SmugMug API does not support batch operations. To improve the performance, pysmug offers a batchable interface which can greatly decrease the time required to perform these operations.

Details

To quickly query all the EXIF information for an album:

>>> import pysmug
>>> m = pysmug.login_anonymously(apiKey)
>>> b = m.batch()
>>> for a in m.images_get(AlbumID=albumId):
...   b.images_getEXIF(ImageID=a['id'])
>>> for (params, value) in b():
...   print value['Image']
>>>

The reason this is so much faster is pysmug is performing all the requests in parallel rather than serially. This is achieved by using PycURL's multi interface. The total time for the operation drops from the sum of all time to the max of all time, which for large albums can result in dramatic performance improvements. This doesn't apply to read operations alone, uploading of images can also happen in parallel.

API

Params

The batchable API differs slightly from the synchronous API because the order of results is non-deterministic. In order to aide in handling the relationship between request and response, each response includes the parameters issued in the request as a tuple of:

(params, value)

Callable

As seen in the example above, to execute the batch of operations simply call the batchable instance. This will return a generator of results as they are made available. It is important to note order is non-deterministic -- results are returned as the request is completed.


Sign in to add a comment
Hosted by Google Code