Access to CKAN Datasource

DataStore supports an access to CKAN API. Websites which has CKAN API are listed in the following URL.

http://ckan.org/instances/

Initialize CKAN Datasource

To create DataStore for CKAN access, pass URL offers API. For example, data.gov offers API via:

http://catalog.data.gov/api

In this case, any of following 4 URL formats can be used for DataStore initialization.

In [1]: import pyopendata as pyod

In [2]: pyod.DataStore('http://catalog.data.gov/api')
Out[2]: CKANStore (http://catalog.data.gov)

In [3]: pyod.DataStore('http://catalog.data.gov/api/')
Out[3]: CKANStore (http://catalog.data.gov)

In [4]: pyod.DataStore('http://catalog.data.gov')
Out[4]: CKANStore (http://catalog.data.gov)

In [5]: pyod.DataStore('http://catalog.data.gov/')
Out[5]: CKANStore (http://catalog.data.gov)

Important

DateStore validates the input URL using CKAN site_read function. If this function is closed on the target website, initialization should fail. In this case, instantiate pyod.CKANStore directly.

For example, data.go.jp doesn’t allow to use site_read.

# should fail
In [6]: pyod.DataStore('http://www.data.go.jp/data')
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-523a640bdcc0> in <module>()
----> 1 pyod.DataStore('http://www.data.go.jp/data')

/home/docs/checkouts/readthedocs.org/user_builds/pyopendata/envs/latest/local/lib/python2.7/site-packages/pyopendata-0.0.3.dev-py2.7.egg/pyopendata/base.pyc in __new__(cls, kind_or_url, proxies)
    172             if store.is_valid():
    173                 return store
--> 174         raise ValueError('Unable to initialize DataStore with {0}'.format(kind_or_url))
    175 
    176     def __init__(self, kid_or_url=None, proxies=None):

ValueError: Unable to initialize DataStore with http://www.data.go.jp/data

# should be OK
In [7]: pyod.CKANStore('http://www.data.go.jp/data')
Out[7]: CKANStore (http://www.data.go.jp/data)

Read Data

Once you create DataStore, you can access to data as described in Basic Usage.