Skip to main content

Utilities for ckan extensions.

Project description

The Natural History Museum logo.

ckantools

CKAN Python

Utilities and common methods for CKAN extensions.

Overview

A collection of methods, decorators, and anything else that might be useful.

ckantools is still very much in development, and is prone to frequent changes that may or may not work.

Installation

pip install ckantools

Usage

See the full usage docs on readthedocs.io.

Actions

Use the @action decorator to add actions:

# logic/actions/module_name.py

from ckantools.decorators import action

@action(schema, helptext, get=False, *other_decorators)
def example_action(parameter_1, parameter_2):
    # ...

Or the @basic_action decorator if you want to load the action but don't want any of the other features (schema loading, auto auth, etc):

from ckantools.decorators import basic_action

@basic_action
def example_action(context, data_dict):
    # ...

And then load the action(s) in plugin.py:

# plugin.py

from .logic.actions import module_name
from ckantools.loaders import create_actions
from ckan.plugins import implements, interfaces, SingletonPlugin

class ExamplePlugin(SingletonPlugin):
    implements(interfaces.IActions)

    # IActions
    def get_actions(self):
        return create_actions(module_name)

Auth

Loading auth functions is similar to actions, i.e. use the @auth decorator.

# logic/auth/module_name.py

from ckantools.decorators import auth

@auth(anon=True)
def example_action(context, data_dict):
    return {'success': True}

@auth('example_action')
def other_action(context, data_dict):
    # checks access to example_action first
    return {'success': True}

The auth functions can then be loaded in plugin.py:

# plugin.py

from .logic.auth import module_name
from ckantools.loaders import create_auth
from ckan.plugins import implements, interfaces, SingletonPlugin

class ExamplePlugin(SingletonPlugin):
    implements(interfaces.IActions)

    # IAuthFunctions
    def get_auth_functions(self):
        return create_auth(module_name)

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

ckantools-0.6.0.tar.gz (24.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ckantools-0.6.0-py3-none-any.whl (26.9 kB view details)

Uploaded Python 3

File details

Details for the file ckantools-0.6.0.tar.gz.

File metadata

  • Download URL: ckantools-0.6.0.tar.gz
  • Upload date:
  • Size: 24.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ckantools-0.6.0.tar.gz
Algorithm Hash digest
SHA256 fba60828190a80de37794ad24b77f733e34e4e4f467316f1c835823007740b54
MD5 6f91cc1fd2568b6c49355eb677be53ef
BLAKE2b-256 452d095897d65c3d6f04fa243a8aaa29a3606a0fa251b005f112939205227323

See more details on using hashes here.

File details

Details for the file ckantools-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: ckantools-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 26.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ckantools-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c18740fe4239e8711bf41d0511c4658bb97f4dfe885f1ecf777b4797d4780b87
MD5 112608b00b904a6c9807b0c23741ac04
BLAKE2b-256 a7bfd31415a79189f5f343fa97bb3550d8351ff11b6795c0296849590f15fb0f

See more details on using hashes here.

Supported by

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