Skip to main content

A library for mapping CKAN metadata <=> Frictionless metadata.

Project description

Frictionless CKAN Mapper

A library for mapping CKAN metadata <=> Frictionless metadata.

The library has zero dependencies (not even on Data Package libs). You can use it directly or use it for inspiration. Detailed outline of the algorithm is in the docs or you can read the code.

Travis Coveralls PyPi SemVer Chat on Discord

Installation

  • Python: install Python. The library is compatible with both Python 2.7+ and Python 3.3+.
pip install frictionless-ckan-mapper

Note: The package is installed as frictionless-ckan-mapper and then imported as frictionless_ckan_mapper.

Getting started

CKAN => Frictionless

# get a CKAN metadata item
ckan_dataset = {
  "name": "my-dataset",
  "title": "My awesome dataset",
  "url": "http://www.example.com/data.csv"
}

# or load from an API e.g.
# ckan_dataset = json.load(urllib.urlopen(
#     https://demo.ckan.org/api/3/package_show?id=my_dataset
# ))

from frictionless_ckan_mapper import ckan_to_frictionless as converter

# convert to frictionless
frictionless_package = converter.dataset(ckan_dict)

print(frictionless_package)

Frictionless => CKAN

frictionless = {
  'name': "f11s-dataset",
  'path': "https://datahub.io/data.csv"
}

from frictionless_ckan_mapper import frictionless_to_ckan as f2c

ckanout = f2c.dataset(frictionless)

print(ckanout)

Reference

This package contains two modules:

  • frictionless_to_ckan
  • ckan_to_frictionless

You can import them directly like so:

from frictionless_ckan_mapper import ckan_to_frictionless
from frictionless_ckan_mapper import frictionless_to_ckan

ckan_to_frictionless

resource(ckandict)

from frictionless_ckan_mapper import ckan_to_frictionless as converter

# ... Some code with a CKAN dictionary ...

output_frictionless_dict = converter.resource(ckan_dictionary)

dataset(ckandict)

from frictionless_ckan_mapper import ckan_to_frictionless as converter

# ... Some code with a CKAN dictionary ...

output_frictionless_dict = converter.dataset(ckan_dictionary)

frictionless_to_ckan

resource(fddict)

from frictionless_ckan_mapper import frictionless_to_ckan as converter

# ... Some code with a Frictionless dictionary ...

output_ckan_dict = converter.resource(frictionless_dictionary)

package(fddict)

from frictionless_ckan_mapper import frictionless_to_ckan as converter

# ... Some code with a Frictionless dictionary ...

output_ckan_dict = converter.package(frictionless_dictionary)

Design

Frictionless   <=>        CKAN
--------------------------------------
Data Package   <=>   Package (Dataset)
Data Resource  <=>   Resource
Table Schema   <=>   Data Dictionary?? (datastore resources can have schemas)

CKAN reference

Summary:

classDiagram

class Package
class Resource
class DataDictionary

Package *-- Resource
Resource o-- DataDictionary

mermaid-diagram-20200703112520

Source for CKAN metadata structure:

Algorithm: CKAN => Frictionless

For Package and Resource

  1. Expand extras into the dict.
  2. Map those attributes we have known mappings for (and parse items with values e.g. a schema will be un-jsonified).
  3. Drop anything we explicitly drop, e.g. package_id on a resource object.
  4. Copy everything else over as is.

Optional extras:

  • Add a profile field

Algorithm: Frictionless => CKAN

Developers

Install the source

  • Clone the repo:

    git clone https://github.com/frictionlessdata/frictionless-ckan-mapper.git
    
  • And install it with pip:

    pip install -e .
    

Run the tests

Use the excellent pytest suite as follows:

pytest tests

To test under both Python 2 and Python 3 environments, we use tox. You can run the following command:

make test

Note: Make sure that the necessary Python versions are in your environment PATH (Python 2.7 and Python 3.6).

Building and publishing the package

To see a list of available commands from the Makefile, execute:

make list

Build the distribution package

make dist

Alternatively, this command will accomplish the same to build packages for both Python 2 and Python 3:

python setup.py sdist bdist_wheel --universal

Test the package at test.pypy.org

python -m twine upload --repository testpypi dist/*

The package will be publicly available at https://test.pypi.org/project/frictionless-ckan-mapper/ and you will be able to pip install it as usual.

Tag a new Git release and publish to PyPi

Note: You will need to publish from your personal PyPi account and be given access as a contributor to the project.

Make sure to update the version of the package in the file frictionless_ckan_mapper/VERSION. Then:

make release

You can quickly review the version to release with make version, which will print the current version stored in VERSION.

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

frictionless-ckan-mapper-1.0.tar.gz (226.7 kB view details)

Uploaded Source

Built Distribution

frictionless_ckan_mapper-1.0-py2.py3-none-any.whl (8.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file frictionless-ckan-mapper-1.0.tar.gz.

File metadata

  • Download URL: frictionless-ckan-mapper-1.0.tar.gz
  • Upload date:
  • Size: 226.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.2

File hashes

Hashes for frictionless-ckan-mapper-1.0.tar.gz
Algorithm Hash digest
SHA256 b934fc34b2e5ecf1ae19d250f7585d8c7e76e846cfb8f6f753e14cb09ea28acd
MD5 2528dd3ff465635df3344456a2c53f15
BLAKE2b-256 704f97985efcb1e48b47728cb7e75134eb0641d61ed404f8f61922f735a50037

See more details on using hashes here.

File details

Details for the file frictionless_ckan_mapper-1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: frictionless_ckan_mapper-1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.2

File hashes

Hashes for frictionless_ckan_mapper-1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 1eae0c723202ff97073624ff10832807cb80711bf866e5d61590455dd3721b8d
MD5 02bd0c4e393f4fa5d1738c1da23b58b3
BLAKE2b-256 6e5be40814efa5f5c00e4b45c89ef59b7da6d0fc029244755d8d1b02bb7f723d

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