Skip to content

okfn/ckanext-validate

Repository files navigation

Tests

ckanext-validate

A simple CKAN extension to validate tabular data powered by frictionless data.

Requirements

Compatibility with core CKAN versions:

CKAN version Compatible?
2.10 not tested
2.11 yes

Installation

To install ckanext-validate:

  1. Activate your CKAN virtual environment, for example:

    . /usr/lib/ckan/default/bin/activate

  2. Clone the source and install it on the virtualenv

    git clone https://github.com/okfn/ckanext-validate.git cd ckanext-validate pip install -e . pip install -r requirements.txt

  3. Add validate to the ckan.plugins setting in your CKAN config file (by default the config file is located at /etc/ckan/default/ckan.ini).

  4. Run the database migration to create the resource_validation table:

    ckan db upgrade -p validate

  5. Restart CKAN. For example if you've deployed CKAN with Apache on Ubuntu:

    sudo service apache2 reload

Usage

Only CSV resources can be validated. Each validation run is stored as a new row in resource_validation — previous results are not overwritten, so a full history is kept. In addition to the dedicated table, the resource extras (validation_status, validation_error_count, validation_errors) are also updated for backwards compatibility.

resource_validate

Validates a CSV resource using Frictionless and persists the result.

Permissions: requires resource_update on the resource.

Parameters:

Name Type Required Description
id string yes The resource id

Example:

curl -X POST \
  -H "Authorization: <your-api-token>" \
  -H "Content-Type: application/json" \
  -d '{"id": "<resource-id>"}' \
  "http://localhost:5000/api/3/action/resource_validate"

Response: the updated resource dict with validation_status and validation_error_count fields.

resource_validation_show

Returns the latest validation result for a given resource.

Permissions: public for any user who can view the resource.

Parameters:

Name Type Required Description
id string yes The resource id

Example:

curl -X POST \
  -H "Authorization: <your-api-token>" \
  -H "Content-Type: application/json" \
  -d '{"id": "<resource-id>"}' \
  "http://localhost:5000/api/3/action/resource_validation_show"

Response:

{
  "success": true,
  "result": {
    "id": 1,
    "resource_id": "<resource-id>",
    "status": "failure",
    "error_count": 2,
    "errors": [
      {
        "row": 5,
        "field": "date",
        "message": "Type error in the cell \"abc\" in row \"5\" and field \"date\""
      }
    ],
    "created": "2026-03-19T14:50:32.364757"
  }
}

Raises ObjectNotFound (HTTP 404) if no validation has been run for the resource yet.

Validation result fields

Field Type Description
id integer Auto-incremented primary key
resource_id string CKAN resource UUID
status string "success" or "failure"
error_count integer Number of validation errors found
errors list List of error objects with row, field, message
created string ISO 8601 UTC timestamp of when the run occurred

Config settings

None at present

TODO: Document any optional config settings here. For example:

# The minimum number of hours to wait before re-checking a resource
# (optional, default: 24).
ckanext.validate.some_setting = some_default_value

Developer installation

To install ckanext-validate for development, activate your CKAN virtualenv and do:

git clone https://github.com/okfn/ckanext-validate.git
cd ckanext-validate
pip install -e .
pip install -r dev-requirements.txt

Tests

To run the tests, do:

pytest --ckan-ini=test.ini

License

AGPL

About

A simple CKAN extension to validate tabular data.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors