A Python library for interacting with CKAN instances
MIT License
ckanutils is a Python library for interacting with remote and local CKAN instances. It uses ckanapi under the hood, and is essentially a high level wrapper for it. A command line interface built on top of this library is available at ckanny.
With ckanutils, you can
ckanutils has been tested on the following configuration:
ckanutils requires the following in order to run properly:
(You are using a virtualenv, right?)
sudo pip install ckanutils
ckanutils is intended to be used directly from Python.
Fetch a remote resource
from ckanutils import CKAN
ckan = CKAN(remote='http://demo.ckan.org')
resource_id = '36f33846-cb43-438e-95fd-f518104a32ed'
r, filepath = ckan.fetch_resource(resource_id, filepath='path/to/file.csv')
print(r.encoding)
Fetch a local resource
from ckanutils import CKAN
ckan = CKAN(api_key='mykey', remote=None)
resource_id = '36f33846-cb43-438e-95fd-f518104a32ed'
r, filepath = ckan.fetch_resource(resource_id, filepath='path/to/file.csv')
print r.encoding
show data
from ckanutils import CKAN
ckan = CKAN(api_key='mykey', remote=None)
resource_id = '36f33846-cb43-438e-95fd-f518104a32ed'
r = ckan.datastore_search(resource_id)
print r.next()
ckanutils will use the following Environment Variables if set:
Environment Variable | Description |
---|---|
CKAN_API_KEY | Your CKAN API Key |
CKAN_REMOTE_URL | Your CKAN instance remote url |
CKAN_USER_AGENT | Your user agent |
In order to support file hashing, ckanutils creates a hash table resource called hash_table.csv
with the following schema:
field | type |
---|---|
datastore_id | text |
hash | text |
By default the hash table resource will be placed in the package hash_table
. ckanutils will create this package if it doesn't exist. Optionally, you can set the hash table package in the command line with the -H, --hash-table
option, or in a Python file as the hash_table
keyword argument to api.CKAN
.
Example:
from ckanutils import api
ckan = api.CKAN(hash_table='custom_hash_table')
hash = ckan.get_hash('36f33846-cb43-438e-95fd-f518104a32ed')
ckanutils comes with a built in task manager manage.py
and a Makefile
.
pip install -r dev-requirements.txt
Run python linter and nose tests
manage lint
manage test
Or if make
is more your speed...
make lint
make test
View CONTRIBUTING.rst
ckanutils is distributed under the MIT License, the same as ckanapi.