Skip to main content

Utilities for ckan extensions.

Project description

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.4.0.tar.gz (23.5 kB view details)

Uploaded Source

Built Distribution

ckantools-0.4.0-py3-none-any.whl (25.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ckantools-0.4.0.tar.gz
  • Upload date:
  • Size: 23.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for ckantools-0.4.0.tar.gz
Algorithm Hash digest
SHA256 5da041ea5dc062bc58a29450de6918345ef654f9ddccb4c6af1d808573a5491b
MD5 0d85b184f4396e475da4ef4a73dd810b
BLAKE2b-256 ec01b70106f081c551f2688f2413b9275966ab92905af7bd1b75737ba9d1ef22

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ckantools-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 25.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for ckantools-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7ec59052920147ba608de5cd593c7638a2c96a15ef99e0d594db2d5912951903
MD5 f7c2b3000e3f84a0af15a3d56d1947e6
BLAKE2b-256 bdec41defe9a8b5bd81fc6a621782661172821e66fcc3942905194cd242b1286

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