一个映射CKAN元数据与Frictionless元数据的库。
项目描述
Frictionless CKAN Mapper
一个映射CKAN元数据与Frictionless元数据的库。
该库没有依赖项(甚至不包括数据包库)。您可以直接使用它,或者将其作为灵感来源。算法的详细说明在文档中,您也可以阅读代码。
安装
- Python:安装Python。该库与Python 2.7+和Python 3.3+兼容。
pip install frictionless-ckan-mapper
注意:该包作为frictionless-ckan-mapper
安装,然后作为frictionless_ckan_mapper
导入。
入门
CKAN => 无摩擦
# 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)
无摩擦 => 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)
参考
此包包含两个模块
frictionless_to_ckan
ckan_to_frictionless
您可以直接导入它们,如下所示
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)
设计
Frictionless <=> CKAN
--------------------------------------
Data Package <=> Package (Dataset)
Data Resource <=> Resource
Table Schema <=> Data Dictionary?? (datastore resources can have schemas)
CKAN参考
摘要
- 以下是关键对象(不含属性)的类图
- 具有其属性的此电子表格中的对象:https://docs.google.com/spreadsheets/d/1XdqGTFni5Jfs8AMbcbfsP7m11h9mOHS0eDtUZtqGVSg/edit#gid=1925460244
classDiagram
class Package
class Resource
class DataDictionary
Package *-- Resource
Resource o-- DataDictionary
CKAN元数据结构的源
- 数据集(包):https://docs.ckan.org/en/2.8/api/index.html#ckan.logic.action.create.package_create
Package.as_dict
方法:https://github.com/ckan/ckan/blob/2.8/ckan/model/package.py#L195-L223package_show
...
算法:CKAN => 无摩擦
在frictionless_ckan_mapper/ckan_to_frictionless.py
中查看代码
算法:无摩擦 => CKAN
在frictionless_ckan_mapper/frictionless_to_ckan.py
中查看代码
开发者
安装源代码
-
克隆仓库
git clone https://github.com/frictionlessdata/frictionless-ckan-mapper.git
-
然后使用pip安装它
pip install -e .
运行测试
使用出色的pytest
套件,如下所示
pytest tests
为了在Python 2和Python 3环境中进行测试,我们使用tox
。您可以运行以下命令
make test
注意:请确保您的环境中包含必要的Python版本PATH
(Python 2.7和Python 3.6)。
构建和发布包
要查看Makefile
中可用的命令列表,请执行
make list
本地构建用于测试的发行包
如果存在先前的构建,请确保在重新构建之前将其删除
make distclean
然后
make dist
或者,此命令将构建Python 2和Python 3的包
python setup.py sdist bdist_wheel --universal
在test.pypi.org测试包
python -m twine upload --repository testpypi dist/*
该包将在https://test.pypi.org/project/frictionless-ckan-mapper/上公开可用,并且您可以使用通常的方法pip install
。
标记新的Git版本并发布到官方PyPi
请确保更新文件frictionless_ckan_mapper/VERSION
中包的版本。然后
make release
您可以使用make version
快速查看要发布的版本,它将打印存储在VERSION
中的当前版本。
项目详情
下载文件
下载适用于您的平台文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源分布
构建分发
哈希 为 frictionless_ckan_mapper-1.0.9-py2.py3-none-any.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | d95af2d5a56bf1a300a0a20c713067e98d0b71a54cd7dfc3acb737dd4db3f968 |
|
MD5 | c09b033c4d0ace02a40d6a397df856e7 |
|
BLAKE2b-256 | b9602e01c7e6fca00f3763f24ea1f960a0830709eba36846f013740341e783d9 |