python - 如何扩展 CKAN API?

标签 python ckan

我想问一下如何通过编写自己的 CKAN 扩展来扩展 CKAN 的 API。我在文档中找不到任何内容。 能举个简单的例子吗?

最佳答案

在 OP 的辩护中,文档似乎确实有点不透明。我一直在研究这个,试图获得一个自定义 API 操作来提供 JSON 新闻提要,并最终想出了这个:

import ckan.plugins as plugins
import ckan.plugins.toolkit as toolkit

# Required so that GET requests work
@toolkit.side_effect_free
def get_news(context,data_dict=None):
  # The actual custom API method
  return {"hello":"world"}


class CustomAPIPlugin(plugins.SingletonPlugin):
  plugins.implements(plugins.interfaces.IActions)

  def get_actions(self):
    # Registers the custom API method defined above
    return {'get_news': get_news}

描述创建身份验证插件的教程在这里:

http://docs.ckan.org/en/latest/extensions/tutorial.html#creating-a-new-extension

我所做的是剽窃,但使用 IActions 而不是 IAuthFunctions:

http://docs.ckan.org/en/latest/extensions/plugin-interfaces.html

它正在安装 CKAN 2.2.1。

关于python - 如何扩展 CKAN API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28043973/

相关文章:

fiware - 如何使用 cygnus 将多个猎户座实体组合到一个 ckan 数据集?

python - 尝试使用本地存储 : Permission Denied 设置 CKAN 文件存储时出错

python - Python 中的面板概率

python - Google 应用引擎 dev_appserver.py 问题

python - 按 Null/Is Not Null 过滤 Django Admin

java - 通过 Java 客户端将文件上传到 CKAN/datahub.io 中的数据集

python - 如何为由其引用表示的长字符串开始一个新行?

python - 索引到列表中的字符串

opendata - CKAN:收获特殊数据集

preview - 机器可读性 : Guidelines to follow such that data can be previewed nicely on CKAN