UsageΒΆ

To use Durga in a project define a class that extends durga.resource.Resource. This example uses the Flickr API flickr.photos.search:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import durga


class FlickrResource(durga.Resource):
    base_url = 'https://api.flickr.com/services'
    name = 'rest'
    results_path = ('photos', 'photo')
    schema = durga.schema.Schema({
        'farm': durga.schema.Use(int),
        'id': durga.schema.Use(int),
        'isfamily': durga.schema.Use(bool),
        'isfriend': durga.schema.Use(bool),
        'ispublic': durga.schema.Use(bool),
        'owner': durga.schema.And(basestring, len),
        'secret': durga.schema.And(basestring, len),
        'server': durga.schema.Use(int),
        'title': durga.schema.And(basestring, len),
    })
    query = {
        'method': 'flickr.photos.search',
        'api_key': 'a33076a7ae214c0d12931ae8e38e846d',
        'format': 'json',
        'nojsoncallback': 1,
    }

Note

For convenience durga.resource.Resource and the schema library are available at the top module level.

Now you can search for the first 10 cat images:

FlickrResource().collection.filter(text='Cat', per_page=10)

This will return a durga.collection.Collection with a durga.element.Element for each result.