Skip to main content

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

Install it from the Python Package Index:

$ pip install ckan-client

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.

Development

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

To run tests:

$ poetry run pytest

License

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

Metadata

Release files for ckan-client 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ckan-client 0.1.1
File Size Uploaded
ckan-client-0.1.1.tar.gz 7.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ckan-client 0.1.1
File Interpreter ABI Platform
ckan_client-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.8 kB

Release files / ckan-client-0.1.1.tar.gz

Download URL ckan-client-0.1.1.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9decf7fd8b96ed25c0a0c846b1cd20a5aa0351ec64c4286ccea03d61b91bee15
BLAKE2b-256 checksum
How to use checksums
7f78af2b1f35cc2aa07b0095ef6e9a67f6f88479caf1d270d4d6169f75f13011
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.10 CPython/3.8.2 Linux/4.19.0-11-amd64

Release files / ckan_client-0.1.1-py3-none-any.whl

Download URL ckan_client-0.1.1-py3-none-any.whl
Size 10.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c6010d6473cd82eb53715e465fac405cde7ef82134da1d54be5dc4ddb135c590
BLAKE2b-256 checksum
How to use checksums
916ff1d4ffbf9595fb4630bffa2cd0fc2f76a723824871c585d0b309e33a7d3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.10 CPython/3.8.2 Linux/4.19.0-11-amd64

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page