Skip to main content

CKAN Python SDK for CKAN3 instances with CKAN3 cloud storage.

Project description

CKAN Client: Python SDK

contributions welcome ckan-client-py actions The MIT License

CKAN 3 SDK for CKAN instances with CKAN v3 style cloud storage.
This SDK will communicate with ckanext-authz-service (using CKAN to provide authorization tokens for other related systems) and Giftless (a highly customizable and extensible Git LFS server implemented in Python) to upload data to blob storage.

Read more about it's design.

Install

All you need is Git, and Python 3.6+ with a PEP 527 compliant tool, such as Poetry.

First, clone this repository:

$ git clone https://github.com/datopian/ckan-client-py.git

Then, move to is directory:

$ cd ckan-client-py

And install the package and its dependencies, for example, with Poetry:

$ poetry install

Usage

ckanclient.Client

Arguments:

Name Description
api_url CKAN API key
api_key CKAN instance URL
organization Organization
dataset_id Dataset id
lfs_url Git LFS URL

Example:

from ckanclient import Client


client = Client(
    '771a05ad-af90-4a70-beea-cbb050059e14',
    'http://localhost:5000',
    'datopian',
    'dailyprices',
    'http://localhost:9419',
)

These settings matches the standard of ckanext-blob-storage development environment, but you still need to create the user and organization there.

ckanclient.Client.action

Arguments:

Name Type Default Description
name str (required) The action name, for example, site_read, package_show
payload dict (required) The payload being sent to CKAN. If a payload is provided for a GET request, it will be converted to URL parameters and each key will be converted to snake case.
http_get bool False Optional, if True will make GET request, otherwise POST.
transform_payload function None Function to mutate the payload before making the request (useful to convert to and from CKAN and Frictionless formats).
transform_response function None function to mutate the response data before returning it (useful to convert to and from CKAN and Frictionless formats).

This method is used internally by the following methods.

ckanclient.Client.create

Arguments:

Name Type Description
dataset_name_or_metadata str or dict It is either a string being a valid dataset name or dictionary with meta-data for the dataset in Frictionless format.

Example:

dataset = client.create('dailyprices')

ckanclient.Client.push

Arguments:

Name Type Description
dataset_metadata dict Dataset meta-data in Frictionless format.

Example:

dataset_metadata = {
    'id': '16d6e8d7-a848-48b1-91d0-fd393c1c6c01',
    'name': 'dailyprices',
    'owner_org': '57f97769-a982-4ccd-91f0-1d86dee822e3',
    'title': 'dailyprices',
    'type': 'dataset',
    'contributors': [],
    # …
}
dataset = client.push(dataset_metadata)

ckanclient.Client.retrieve

Arguments:

Name Type Description
name_or_id str Id or name of the dataset.

Example:

dataset = client.retrieve('dailyprices')

ckanclient.Client.push_blob

Arguments:

Name Type Description
resource dict A Frictionless resource.

Tests

To run tests:

$ poetry run pytest

License

This project is licensed under the MIT License - see the LICENSE file for details

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ckan-client-0.1.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

ckan_client-0.1.0-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file ckan-client-0.1.0.tar.gz.

File metadata

  • Download URL: ckan-client-0.1.0.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.8.2 Linux/4.19.0-11-amd64

File hashes

Hashes for ckan-client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9e7a78259e477998b65be66f055cb974b764d0c966245aeb08ee4257a6d4bd10
MD5 fc9b8213ea2f6b3cbe8aa234405ec774
BLAKE2b-256 2f0de73dd8bf14f0f9212d29e3523718963913a165c1d340935d8592f329e38e

See more details on using hashes here.

File details

Details for the file ckan_client-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ckan_client-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.10 CPython/3.8.2 Linux/4.19.0-11-amd64

File hashes

Hashes for ckan_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b13e0ba4a6be3c943a9db8cfa3c62fa73e59e71f3b31cec55cee78d2a9143527
MD5 c5f7adb7df32dce86ceec9b6dbaa134c
BLAKE2b-256 d68b3b01477f12abd8d0eae86f425d59902e6e0d24e4cbbb2cd4644acb6595ed

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page