ckan.logic.action.get

Functions for getting data from CKAN.

ckan.logic.action.get.site_read(context, data_dict=None)

Return True.

Return type:boolean
ckan.logic.action.get.package_list(context, data_dict)

Return a list of the names of the site’s datasets (packages).

Return type:list of strings
ckan.logic.action.get.current_package_list_with_resources(context, data_dict)

Return a list of the site’s datasets (packages) and their resources.

The list is sorted most-recently-modified first.

Parameters:
  • limit (int) – if given, the list of datasets will be broken into pages of at most limit datasets per page and only one page will be returned at a time (optional)
  • page (int) – when limit is given, which page to return
Return type:

list of dictionaries

ckan.logic.action.get.revision_list(context, data_dict)

Return a list of the IDs of the site’s revisions.

Return type:list of strings
ckan.logic.action.get.package_revision_list(context, data_dict)

Return a dataset (package)’s revisions as a list of dictionaries.

Parameters:id (string) – the id or name of the dataset
ckan.logic.action.get.related_show(context, data_dict=None)

Return a single related item.

Parameters:id (string) – the id of the related item to show
Return type:dictionary
ckan.logic.action.get.related_list(context, data_dict=None)

Return a dataset’s related items.

Either the id or the dataset parameter must be given.

Parameters:
  • id (string) – id or name of the dataset (optional)
  • dataset (dictionary) – dataset dictionary of the dataset (optional)
  • type_filter (string) – the type of related item to show (optional, default: None, show all items)
  • sort (string) – the order to sort the related items in, possible values are ‘view_count_asc’, ‘view_count_desc’, ‘created_asc’ or ‘created_desc’ (optional)
  • featured (bool) – whether or not to restrict the results to only featured related items (optional, default: False)
Return type:

list of dictionaries

ckan.logic.action.get.member_list(context, data_dict=None)

Return the members of a group.

The user must have permission to ‘get’ the group.

Parameters:
  • id (string) – the id or name of the group
  • object_type (string) – restrict the members returned to those of a given type, e.g. 'user' or 'package' (optional, default: None)
  • capacity (string) – restrict the members returned to those with a given capacity, e.g. 'member', 'editor', 'admin', 'public', 'private' (optional, default: None)
Return type:

list of (id, type, capacity) tuples

ckan.logic.action.get.group_list(context, data_dict)

Return a list of the names of the site’s groups.

Parameters:
  • order_by (string) – the field to sort the list by, must be 'name' or 'packages' (optional, default: 'name') Deprecated use sort.
  • sort (string) – sorting of the search results. Optional. Default: “name asc” string of field name and sort-order. The allowed fields are ‘name’ and ‘packages’
  • groups (list of strings) – a list of names of the groups to return, if given only groups whose names are in this list will be returned (optional)
  • all_fields (boolean) – return full group dictionaries instead of just names (optional, default: False)
Return type:

list of strings

ckan.logic.action.get.organization_list(context, data_dict)

Return a list of the names of the site’s organizations.

Parameters:
  • order_by (string) – the field to sort the list by, must be 'name' or 'packages' (optional, default: 'name') Deprecated use sort.
  • sort (string) – sorting of the search results. Optional. Default: “name asc” string of field name and sort-order. The allowed fields are ‘name’ and ‘packages’
  • organizations (list of strings) – a list of names of the groups to return, if given only groups whose names are in this list will be returned (optional)
  • all_fields (boolean) – return full group dictionaries instead of just names (optional, default: False)
Return type:

list of strings

ckan.logic.action.get.group_list_authz(context, data_dict)

Return the list of groups that the user is authorized to edit.

Parameters:available_only (boolean) – remove the existing groups in the package (optional, default: False)
Returns:the names of groups that the user is authorized to edit
Return type:list of strings
ckan.logic.action.get.organization_list_for_user(context, data_dict)

Return the list of organizations that the user is a member of.

Parameters:permission (string) – the permission the user has against the returned organizations (optional, default: edit_group)
Returns:the names of organizations the user is authorized to do specific permission
Return type:list of strings
ckan.logic.action.get.group_revision_list(context, data_dict)

Return a group’s revisions.

Parameters:id (string) – the name or id of the group
Return type:list of dictionaries
ckan.logic.action.get.licence_list(context, data_dict)

Return the list of licenses available for datasets on the site.

Return type:list of dictionaries
ckan.logic.action.get.tag_list(context, data_dict)

Return a list of the site’s tags.

By default only free tags (tags that don’t belong to a vocabulary) are returned. If the vocabulary_id argument is given then only tags belonging to that vocabulary will be returned instead.

Parameters:
  • query (string) – a tag name query to search for, if given only tags whose names contain this string will be returned (optional)
  • vocabulary_id (string) – the id or name of a vocabulary, if give only tags that belong to this vocabulary will be returned (optional)
  • all_fields (boolean) – return full tag dictionaries instead of just names (optional, default: False)
Return type:

list of dictionaries

ckan.logic.action.get.user_list(context, data_dict)

Return a list of the site’s user accounts.

Parameters:
  • q (string) – restrict the users returned to those whose names contain a string (optional)
  • order_by (string) – which field to sort the list by (optional, default: 'name')
Return type:

list of dictionaries

ckan.logic.action.get.package_relationships_list(context, data_dict)

Return a dataset (package)’s relationships.

Parameters:
  • id (string) – the id or name of the package
  • id2
  • rel
Return type:

list of dictionaries

ckan.logic.action.get.package_show(context, data_dict)

Return the metadata of a dataset (package) and its resources.

Parameters:id (string) – the id or name of the dataset
Return type:dictionary
ckan.logic.action.get.resource_show(context, data_dict)

Return the metadata of a resource.

Parameters:id (string) – the id of the resource
Return type:dictionary
ckan.logic.action.get.resource_status_show(context, data_dict)

Return the statuses of a resource’s tasks.

Parameters:id (string) – the id of the resource
Return type:list of (status, date_done, traceback, task_status) dictionaries
ckan.logic.action.get.revision_show(context, data_dict)

Return the details of a revision.

Parameters:id (string) – the id of the revision
Return type:dictionary
ckan.logic.action.get.group_show(context, data_dict)

Return the details of a group.

Parameters:id (string) – the id or name of the group
Return type:dictionary
ckan.logic.action.get.organization_show(context, data_dict)

Return the details of a organization.

Parameters:id (string) – the id or name of the organization
Return type:dictionary
ckan.logic.action.get.group_package_show(context, data_dict)

Return the datasets (packages) of a group.

Parameters:
  • id (string) – the id or name of the group
  • limit (int) – the maximum number of datasets to return (optional)
Return type:

list of dictionaries

ckan.logic.action.get.tag_show(context, data_dict)

Return the details of a tag and all its datasets.

Parameters:id (string) – the name or id of the tag
Returns:the details of the tag, including a list of all of the tag’s datasets and their details
Return type:dictionary
ckan.logic.action.get.user_show(context, data_dict)

Return a user account.

Either the id or the user_obj parameter must be given.

Parameters:
  • id (string) – the id or name of the user (optional)
  • user_obj (user dictionary) – the user dictionary of the user (optional)
Return type:

dictionary

ckan.logic.action.get.package_autocomplete(context, data_dict)

Return a list of datasets (packages) that match a string.

Datasets with names or titles that contain the query string will be returned.

Parameters:q (string) – the string to search for
Return type:list of dictionaries
ckan.logic.action.get.format_autocomplete(context, data_dict)

Return a list of resource formats whose names contain a string.

Parameters:
  • q (string) – the string to search for
  • limit (int) – the maximum number of resource formats to return (optional, default: 5)
Return type:

list of strings

ckan.logic.action.get.user_autocomplete(context, data_dict)

Return a list of user names that contain a string.

Parameters:
  • q (string) – the string to search for
  • limit (int) – the maximum number of user names to return (optional, default: 20)
Return type:

a list of user dictionaries each with keys 'name', 'fullname', and 'id'

Searches for packages satisfying a given search criteria.

This action accepts solr search query parameters (details below), and returns a dictionary of results, including dictized datasets that match the search criteria, a search count and also facet information.

Solr Parameters:

For more in depth treatment of each paramter, please read the Solr Documentation.

This action accepts a subset of solr’s search query parameters:

Parameters:
  • q (string) – the solr query. Optional. Default: “*:*”
  • fq (string) – any filter queries to apply. Note: +site_id:{ckan_site_id} is added to this string prior to the query being executed.
  • rows (int) – the number of matching rows to return.
  • sort (string) – sorting of the search results. Optional. Default: ‘relevance asc, metadata_modified desc’. As per the solr documentation, this is a comma-separated string of field names and sort-orderings.
  • start (int) – the offset in the complete result for where the set of returned datasets should begin.
  • qf (string) – the dismax query fields to search within, including boosts. See the Solr Dismax Documentation for further details.
  • facet (string) – whether to enable faceted results. Default: “true”.
  • facet.mincount (int) – the minimum counts for facet fields should be included in the results.
  • facet.limit (int) – the maximum number of constraint counts that should be returned for the facet fields. A negative value means unlimited
  • facet.field (list of strings) – the fields to facet upon. Default empty. If empty, then the returned facet information is empty.

Results:

The result of this action is a dict with the following keys:

Return type:

A dictionary with the following keys

Parameters:
  • count (int) – the number of results found. Note, this is the total number of results found, not the total number of results returned (which is affected by limit and row parameters used in the input).
  • results (list of dictized datasets.) – ordered list of datasets matching the query, where the ordering defined by the sort parameter used in the query.
  • facets (DEPRECATED dict) – DEPRECATED. Aggregated information about facet counts.
  • search_facets (nested dict of dicts.) – aggregated information about facet counts. The outer dict is keyed by the facet field name (as used in the search query). Each entry of the outer dict is itself a dict, with a “title” key, and an “items” key. The “items” key’s value is a list of dicts, each with “count”, “display_name” and “name” entries. The display_name is a form of the name that can be used in titles.

An example result:

{'count': 2,
 'results': [ { <snip> }, { <snip> }],
 'search_facets': {u'tags': {'items': [{'count': 1,
                                        'display_name': u'tolstoy',
                                        'name': u'tolstoy'},
                                       {'count': 2,
                                        'display_name': u'russian',
                                        'name': u'russian'}
                                      ]
                            }
                  }
}

Limitations:

The full solr query language is not exposed, including.

fl
The parameter that controls which fields are returned in the solr query cannot be changed. CKAN always returns the matched datasets as dictionary objects.

Searches for resources satisfying a given search criteria.

It returns a dictionary with 2 fields: count and results. The count field contains the total number of Resources found without the limit or query parameters having an effect. The results field is a list of dictized Resource objects.

The ‘query’ parameter is a required field. It is a string of the form {field}:{term} or a list of strings, each of the same form. Within each string, {field} is a field or extra field on the Resource domain object.

If {field} is "hash", then an attempt is made to match the {term} as a prefix of the Resource.hash field.

If {field} is an extra field, then an attempt is made to match against the extra fields stored against the Resource.

Note: The search is limited to search against extra fields declared in the config setting ckan.extra_resource_fields.

Note: Due to a Resource’s extra fields being stored as a json blob, the match is made against the json string representation. As such, false positives may occur:

If the search criteria is:

query = "field1:term1"

Then a json blob with the string representation of:

{"field1": "foo", "field2": "term1"}

will match the search criteria! This is a known short-coming of this approach.

All matches are made ignoring case; and apart from the "hash" field, a term matches if it is a substring of the field’s value.

Finally, when specifying more than one search criteria, the criteria are AND-ed together.

The order parameter is used to control the ordering of the results. Currently only ordering one field is available, and in ascending order only.

The fields parameter is deprecated as it is not compatible with calling this action with a GET request to the action API.

The context may contain a flag, search_query, which if True will make this action behave as if being used by the internal search api. ie - the results will not be dictized, and SearchErrors are thrown for bad search queries (rather than ValidationErrors).

Parameters:
  • query (string or list of strings of the form “{field}:{term1}”) – The search criteria. See above for description.
  • fields (dict of fields to search terms.) – Deprecated
  • order_by (string) – A field on the Resource model that orders the results.
  • offset (int) – Apply an offset to the query.
  • limit (int) – Apply a limit to the query.
Returns:

A dictionary with a count field, and a results field.

Return type:

dict

Return a list of tags whose names contain a given string.

By default only free tags (tags that don’t belong to any vocabulary) are searched. If the vocabulary_id argument is given then only tags belonging to that vocabulary will be searched instead.

Parameters:
  • query (string or list of strings) – the string(s) to search for
  • vocabulary_id (string) – the id or name of the tag vocabulary to search in (optional)
  • fields (dictionary) – deprecated
  • limit (int) – the maximum number of tags to return
  • offset (int) – when limit is given, the offset to start returning tags from
Returns:

A dictionary with the following keys:

'count'

The number of tags in the result.

'results'

The list of tags whose names contain the given string, a list of dictionaries.

Return type:

dictionary

ckan.logic.action.get.tag_autocomplete(context, data_dict)

Return a list of tag names that contain a given string.

By default only free tags (tags that don’t belong to any vocabulary) are searched. If the vocabulary_id argument is given then only tags belonging to that vocabulary will be searched instead.

Parameters:
  • query (string) – the string to search for
  • vocabulary_id (string) – the id or name of the tag vocabulary to search in (optional)
  • fields (dictionary) – deprecated
  • limit (int) – the maximum number of tags to return
  • offset (int) – when limit is given, the offset to start returning tags from
Return type:

list of strings

ckan.logic.action.get.task_status_show(context, data_dict)

Return a task status.

Either the id parameter or the entity_id, task_type and key parameters must be given.

Parameters:
  • id (string) – the id of the task status (optional)
  • entity_id (string) – the entity_id of the task status (optional)
  • task_type – the task_type of the task status (optional)
  • key (string) – the key of the task status (optional)
Return type:

dictionary

ckan.logic.action.get.term_translation_show(context, data_dict)

Return the translations for the given term(s) and language(s).

Parameters:
  • terms (list of strings) – the terms to search for translations of, e.g. 'Russian', 'romantic novel'
  • lang_codes (list of language code strings) – the language codes of the languages to search for translations into, e.g. 'en', 'de' (optional, default is to search for translations into any language)
Return type:

a list of term translation dictionaries each with keys 'term' (the term searched for, in the source language), 'term_translation' (the translation of the term into the target language) and 'lang_code' (the language code of the target language)

ckan.logic.action.get.roles_show(context, data_dict)

Return the roles of all users and authorization groups for an object.

Parameters:
  • domain_object (string) – a package or group name or id to filter the results by
  • user (string) – a user name or id
Return type:

list of dictionaries

ckan.logic.action.get.status_show(context, data_dict)

Return a dictionary with information about the site’s configuration.

ckan.logic.action.get.vocabulary_list(context, data_dict)

Return a list of all the site’s tag vocabularies.

Return type:list of dictionaries
ckan.logic.action.get.vocabulary_show(context, data_dict)

Return a single tag vocabulary.

Parameters:id (string) – the id or name of the vocabulary
Returns:the vocabulary.
Return type:dictionary
ckan.logic.action.get.user_activity_list(context, data_dict)

Return a user’s public activity stream.

You must be authorized to view the user’s profile.

Parameters:
  • id (string) – the id or name of the user
  • offset (int) – where to start getting activity items from (optional, default: 0)
  • limit (int) – the maximum number of activities to return (optional, default: 31, the default value is configurable via the ckan.activity_list_limit setting)
Return type:

list of dictionaries

ckan.logic.action.get.package_activity_list(context, data_dict)

Return a package’s activity stream.

You must be authorized to view the package.

Parameters:
  • id (string) – the id or name of the package
  • offset (int) – where to start getting activity items from (optional, default: 0)
  • limit (int) – the maximum number of activities to return (optional, default: 31, the default value is configurable via the ckan.activity_list_limit setting)
Return type:

list of dictionaries

ckan.logic.action.get.group_activity_list(context, data_dict)

Return a group’s activity stream.

You must be authorized to view the group.

Parameters:
  • id (string) – the id or name of the group
  • offset (int) – where to start getting activity items from (optional, default: 0)
  • limit (int) – the maximum number of activities to return (optional, default: 31, the default value is configurable via the ckan.activity_list_limit setting)
Return type:

list of dictionaries

ckan.logic.action.get.organization_activity_list(context, data_dict)

Return a organization’s activity stream.

Parameters:id (string) – the id or name of the organization
Return type:list of dictionaries
ckan.logic.action.get.recently_changed_packages_activity_list(context, data_dict)

Return the activity stream of all recently added or changed packages.

Parameters:
  • offset (int) – where to start getting activity items from (optional, default: 0)
  • limit (int) – the maximum number of activities to return (optional, default: 31, the default value is configurable via the ckan.activity_list_limit setting)
Return type:

list of dictionaries

ckan.logic.action.get.activity_detail_list(context, data_dict)

Return an activity’s list of activity detail items.

Parameters:id (string) – the id of the activity
Return type:list of dictionaries.
ckan.logic.action.get.user_activity_list_html(context, data_dict)

Return a user’s public activity stream as HTML.

The activity stream is rendered as a snippet of HTML meant to be included in an HTML page, i.e. it doesn’t have any HTML header or footer.

Parameters:
  • id (string) – The id or name of the user.
  • offset (int) – where to start getting activity items from (optional, default: 0)
  • limit (int) – the maximum number of activities to return (optional, default: 31, the default value is configurable via the ckan.activity_list_limit setting)
Return type:

string

ckan.logic.action.get.package_activity_list_html(context, data_dict)

Return a package’s activity stream as HTML.

The activity stream is rendered as a snippet of HTML meant to be included in an HTML page, i.e. it doesn’t have any HTML header or footer.

Parameters:
  • id (string) – the id or name of the package
  • offset (int) – where to start getting activity items from (optional, default: 0)
  • limit (int) – the maximum number of activities to return (optional, default: 31, the default value is configurable via the ckan.activity_list_limit setting)
Return type:

string

ckan.logic.action.get.group_activity_list_html(context, data_dict)

Return a group’s activity stream as HTML.

The activity stream is rendered as a snippet of HTML meant to be included in an HTML page, i.e. it doesn’t have any HTML header or footer.

Parameters:
  • id (string) – the id or name of the group
  • offset (int) – where to start getting activity items from (optional, default: 0)
  • limit (int) – the maximum number of activities to return (optional, default: 31, the default value is configurable via the ckan.activity_list_limit setting)
Return type:

string

ckan.logic.action.get.organization_activity_list_html(context, data_dict)

Return a organization’s activity stream as HTML.

The activity stream is rendered as a snippet of HTML meant to be included in an HTML page, i.e. it doesn’t have any HTML header or footer.

Parameters:id (string) – the id or name of the organization
Return type:string
ckan.logic.action.get.recently_changed_packages_activity_list_html(context, data_dict)

Return the activity stream of all recently changed packages as HTML.

The activity stream includes all recently added or changed packages. It is rendered as a snippet of HTML meant to be included in an HTML page, i.e. it doesn’t have any HTML header or footer.

Parameters:
  • offset (int) – where to start getting activity items from (optional, default: 0)
  • limit (int) – the maximum number of activities to return (optional, default: 31, the default value is configurable via the ckan.activity_list_limit setting)
Return type:

string

ckan.logic.action.get.user_follower_count(context, data_dict)

Return the number of followers of a user.

Parameters:id (string) – the id or name of the user
Return type:int
ckan.logic.action.get.dataset_follower_count(context, data_dict)

Return the number of followers of a dataset.

Parameters:id (string) – the id or name of the dataset
Return type:int
ckan.logic.action.get.group_follower_count(context, data_dict)

Return the number of followers of a group.

Parameters:id (string) – the id or name of the group
Return type:int
ckan.logic.action.get.user_follower_list(context, data_dict)

Return the list of users that are following the given user.

Parameters:id (string) – the id or name of the user
Return type:list of dictionaries
ckan.logic.action.get.dataset_follower_list(context, data_dict)

Return the list of users that are following the given dataset.

Parameters:id (string) – the id or name of the dataset
Return type:list of dictionaries
ckan.logic.action.get.group_follower_list(context, data_dict)

Return the list of users that are following the given group.

Parameters:id (string) – the id or name of the group
Return type:list of dictionaries
ckan.logic.action.get.am_following_user(context, data_dict)

Return True if you’re following the given user, False if not.

Parameters:id (string) – the id or name of the user
Return type:boolean
ckan.logic.action.get.am_following_dataset(context, data_dict)

Return True if you’re following the given dataset, False if not.

Parameters:id (string) – the id or name of the dataset
Return type:boolean
ckan.logic.action.get.am_following_group(context, data_dict)

Return True if you’re following the given group, False if not.

Parameters:id (string) – the id or name of the group
Return type:boolean
ckan.logic.action.get.followee_count(context, data_dict)

Return the number of objects that are followed by the given user.

Counts all objects, of any type, that the given user is following (e.g. followed users, followed datasets, followed groups).

Parameters:id (string) – the id of the user
Return type:int
ckan.logic.action.get.user_followee_count(context, data_dict)

Return the number of users that are followed by the given user.

Parameters:id (string) – the id of the user
Return type:int
ckan.logic.action.get.dataset_followee_count(context, data_dict)

Return the number of datasets that are followed by the given user.

Parameters:id (string) – the id of the user
Return type:int
ckan.logic.action.get.group_followee_count(context, data_dict)

Return the number of groups that are followed by the given user.

Parameters:id (string) – the id of the user
Return type:int
ckan.logic.action.get.followee_list(context, data_dict)

Return the list of objects that are followed by the given user.

Returns all objects, of any type, that the given user is following (e.g. followed users, followed datasets, followed groups.. ).

Parameters:
  • id (string) – the id of the user
  • q (string) – a query string to limit results by, only objects whose display name begins with the given string (case-insensitive) wil be returned (optional)
Return type:

list of dictionaries, each with keys ‘type’ (e.g. ‘user’, ‘dataset’ or ‘group’), ‘display_name’ (e.g. a user’s display name, or a package’s title) and ‘dict’ (e.g. a dict representing the followed user, package or group, the same as the dict that would be returned by user_show, package_show or group_show)

ckan.logic.action.get.user_followee_list(context, data_dict)

Return the list of users that are followed by the given user.

Parameters:id (string) – the id of the user
Return type:list of dictionaries
ckan.logic.action.get.dataset_followee_list(context, data_dict)

Return the list of datasets that are followed by the given user.

Parameters:id (string) – the id or name of the user
Return type:list of dictionaries
ckan.logic.action.get.group_followee_list(context, data_dict)

Return the list of groups that are followed by the given user.

Parameters:id (string) – the id or name of the user
Return type:list of dictionaries
ckan.logic.action.get.dashboard_activity_list(context, data_dict)

Return the authorized user’s dashboard activity stream.

Unlike the activity dictionaries returned by other *_activity_list actions, these activity dictionaries have an extra boolean value with key is_new that tells you whether the activity happened since the user last viewed her dashboard ('is_new': True) or not ('is_new': False).

The user’s own activities are always marked 'is_new': False.

Parameters:
  • offset (int) – where to start getting activity items from (optional, default: 0)
  • limit – the maximum number of activities to return (optional, default: 31, the default value is configurable via the ckan.activity_list_limit setting)
Return type:

list of activity dictionaries

ckan.logic.action.get.dashboard_activity_list_html(context, data_dict)

Return the authorized user’s dashboard activity stream as HTML.

The activity stream is rendered as a snippet of HTML meant to be included in an HTML page, i.e. it doesn’t have any HTML header or footer.

Parameters:
  • offset (int) – where to start getting activity items from (optional, default: 0)
  • limit (int) – the maximum number of activities to return (optional, default: 31, the default value is configurable via the ckan.activity_list_limit setting)
Return type:

string

ckan.logic.action.get.dashboard_new_activities_count(context, data_dict)

Return the number of new activities in the user’s dashboard.

Return the number of new activities in the authorized user’s dashboard activity stream.

Activities from the user herself are not counted by this function even though they appear in the dashboard (users don’t want to be notified about things they did themselves).

Return type:int