A CKAN extension that lets you attach a flexible, schema-free data dictionary (“resource documentation”) to any resource, not just Datastore-backed ones.
Project description
A CKAN extension that allows attaching a flexible data dictionary (resource documentation) to any resource — not just those backed by the Datastore.
Each resource’s documentation can include a validation schema defined individually using JSON Schema Draft 2020-12, enabling optional enforcement of structure and constraints while maintaining the flexibility of a free-form data dictionary.
The official specification for JSON Schema Draft 2020-12 is available here.
Here is an example of a resource documentation in a format of Datastore fields. But it's not limited to that format, you can save any custom data you need.
It's also possible to define a validation schema for the resource documentation, which will be used to validate the documentation data.
Requirements
Compatibility with core CKAN versions:
| CKAN version | Compatible? |
|---|---|
| 2.9 and earlier | no |
| 2.10+ | yes |
Installation
To install ckanext-resource-docs:
-
Activate your CKAN virtual environment, for example:
. /usr/lib/ckan/default/bin/activate -
Install the extension from PyPI:
pip install ckanext-resource-docs
-
Add
resource_docsto theckan.pluginssetting in your CKAN config file (usually located at/etc/ckan/default/ckan.ini). -
Restart CKAN. For example, if you've deployed CKAN with Apache on Ubuntu:
sudo service apache2 reload
Config settings
The following options control how ckanext-resource-docs behaves.
ckanext.resource_docs.append_docs_to_resource_api
Type: bool
Default: false
When true, resource documentation is automatically included in the standard CKAN resource API response. This allows clients to retrieve documentation without making a separate API call.
[!IMPORTANT] Appending resource documentation to the API response can impact performance and response size.
Example:
ckanext.resource_docs.append_docs_to_resource_api = true
Example API response
With append_docs_to_resource_api = true and the default api_field_name:
{
"id": "resource-id-123",
"name": "my-resource.csv",
"url": "https://example.com/data.csv",
"format": "CSV",
"resource_docs": {
"documentation": "This dataset contains...",
"fields": [
{
"name": "column1",
"description": "Description of column1",
"type": "string"
}
]
}
}
ckanext.resource_docs.api_field_name
Type: string
Default: resource_docs
Specifies the field name in the API response that will contain the resource documentation. Only applies if append_docs_to_resource_api is enabled.
[!WARNING] Ensure, that your schema doesn't use the same field name to avoid conflicts.
Example:
ckanext.resource_docs.api_field_name = documentation
With this setting, the documentation appears under "documentation" field instead of "resource_docs".
ckanext.resource_docs.show_view
Type: bool
Default: false
When true, the resource documentation is displayed in the resource view page in the CKAN web interface.
Example:
ckanext.resource_docs.show_view = true
View example:
Interface
The IResourceDocs interface allows CKAN plugins to extend the behavior of resource documentation extension.
Current methods:
prepopulate_resource_docs- Provide initial documentation using resource metadata.
Example implementation
import json
import ckan.plugins as p
import ckan.logic as tk
from ckanext.resource_docs.interfaces import IResourceDocs
class YourPlugin(p.SingletonPlugin):
"""Example plugin implementing IResourceDocs."""
...
p.implements(IResourceDocs, inherit=True)
def prepopulate_resource_docs(self, resource: dict[str, Any]) -> str:
"""Provide initial documentation using the DataStore Data Dictionary."""
try:
result = tk.get_action("datastore_info")(
{"user": tk.current_user.name if tk.current_user else ""},
{"id": resource["id"]}
)
except (tk.ValidationError, tk.ObjectNotFound):
return ""
return json.dumps(result["fields"])
Developer installation
To install ckanext-resource-docs for development, activate your CKAN virtualenv and do:
git clone https://github.com/DataShades/ckanext-resource-docs.git
cd ckanext-resource-docs
pip install -e .
Tests
To run the tests, do:
pytest --ckan-ini=test.ini
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ckanext_resource_docs-0.4.0.tar.gz.
File metadata
- Download URL: ckanext_resource_docs-0.4.0.tar.gz
- Upload date:
- Size: 335.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8cb0fcae148e7bfb9882671df1c9b15faa1153da196ede23307d91d42b117c5f
|
|
| MD5 |
afa8ed507ddf8dec9c4a728e90aa3220
|
|
| BLAKE2b-256 |
76fdd5f31807cb9fa7198626af0d46fd8b4a85d9c8a32d1c98c894ba4bdfe9e6
|
File details
Details for the file ckanext_resource_docs-0.4.0-py3-none-any.whl.
File metadata
- Download URL: ckanext_resource_docs-0.4.0-py3-none-any.whl
- Upload date:
- Size: 343.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81c2b752161c9ce2705e66a3f9e02ce1bf71fedc84809a871807cbe0bbd64284
|
|
| MD5 |
ef9ae708171afda055fceae03d8ca1cd
|
|
| BLAKE2b-256 |
8264a8b820d3fc4d4f946fb1082064d41ab76a2f869f328bcf470a5f66f657ac
|