Skip to content

Development Overview

Developing a CKAN extension requires organizing code into clean, decoupled architectural layers. Rather than building features inside monolithic files or mixing business logic into web views, modern CKAN extension development follows strict separation of responsibilities.

This guide outlines the overall extension architecture and the step-by-step process for developing new features.


Architectural Layers

Every feature in a CKAN extension is partitioned across predictable layers:

graph TD
    A["Presentation (views, CLI, templates)"] --> B["Logic (actions, auth, validators)"]
    B --> C["Data (SQLAlchemy models, migrations)"]
    B --> D["Events & signals (ISignal subscribers)"]
    E["Entry points (plugin.py & implementations/)"] --> A
    E --> B

The Feature Development Process

When building a new feature or extending existing CKAN capabilities, follow this standard workflow:

  1. Data modeling & persistence

    If the feature introduces new data entities or persistent state beyond core CKAN schemas:

  2. Business logic & action design

    Write pure, reusable business logic in the logic layer:

    • Define action functions inside logic/action/ named with your extension prefix (e.g. myext_item_create).
    • Annotate actions with @tk.validate_action_data(schema) to enforce strict schema verification.
    • Always call tk.check_access() inside action functions to enforce authorization checks.
  3. Plugin registration

    Register entry points and hooks cleanly:

    • Use @tk.blanket decorators on your plugin class in plugin.py to auto-discover actions, auth functions, validators, blueprints, and template helpers.
    • Extract complex CKAN interface implementation methods (e.g. IConfigurer, IPackageController) into an implementations/ submodule rather than cluttering plugin.py.
  4. Presentation & user interfaces

    Expose your business actions to users:

    • Create flask blueprints inside views/ for HTTP web routes.
    • Register CLI commands inside cli.py for administrative or background operations.
    • Expose custom Jinja functions in helpers.py for UI presentation needs.
    • Rule: Views and CLI commands must remain thin wrappers—they extract parameters and invoke tk.get_action(), never executing business logic or raw database queries directly.
  5. Event decoupling & config integration

    Complete the feature integration:

    • Declare custom extension parameters in config_declaration.py with fallback defaults.
    • Use ISignal to broadcast or react to system events without tight coupling.
    • Annotate interface implementations with @override and type hints to maintain strict safety.

Section Map

For detailed syntax, code patterns, and implementation examples, refer to the individual development guides:

  • Defining Plugins — Plugin structure, blanket discovery, and interface implementation setup.
  • Adding Actions — Writing actions, calling conventions, and context handling.
  • Validators — Schema validation rules, custom validators, and @tk.validate_action_data.
  • Adding Views — Flask Blueprints, route definitions, and request handling.
  • CLI Commands — Click CLI command groups and terminal tools.
  • Config Management — Declaration files, config options, and runtime retrieval.
  • Database Models — SQLAlchemy v2 model definitions, session management, and dictize serialization.
  • Database Migrations — Isolated Alembic migrations for extension tables.
  • Signals — Event handling with ISignal interfaces.
  • Template Helpers — Exposing python helper functions to Jinja2 templates.
  • Typing — Type hints, @override annotations, and static checking.