okfn / ckanclient-deprecated

DEPRECATED - please see https://github.com/ckan/ckanapi. [Python client library for CKAN]
http://pypi.python.org/pypi/ckanclient
25 stars 17 forks source link

Add resource_search method to the CkanClient class #26

Open earthquakesan opened 11 years ago

earthquakesan commented 11 years ago

Add a method reflecting CKAN API resource search mechanism. Example (from CKAN API doc): http://demo.ckan.org/api/3/action/resource_search?query=name:District%20Names

rufuspollock commented 11 years ago

Good idea. If you want something right now do:

client = ckanclient.CkanClient(base_location, api_key)
resource_id = 'xyz'
query = 'jones'
client.action('datastore_search',
                 resource_id=resource_id,
                 q=query
                )

See the docs at: http://docs.ckan.org/en/ckan-2.0.1/datastore-api.html#ckanext.datastore.logic.action.datastore_search

Plus also cf https://gist.github.com/rgrp/3813564#file-load-py

davidread commented 10 years ago

I think that we shouldn't add all the action functions as separate functions, in the manner that we did for the API v1/v2. There are so many of them, and they have a pythonic interface, there's not much to gain repeating them in the ckanclient code.

The one improvement that might help would be to allow this syntax:

client.action.datastore_search(
                 resource_id=resource_id,
                 q=query
                )

where 'datastore_search' is not a real method, but captured by def __getattr__(self, name) and it calls the existing action method. This is what is done in the admirable alternative API that focuses exclusively on the action API: https://github.com/wardi/ckanapi