ckan.logic.action.create

Functions for adding data to CKAN.

ckan.logic.action.create.package_create(context, data_dict)

Create a new dataset (package).

You must be authorized to create new datasets. If you specify any groups for the new dataset, you must also be authorized to edit these groups.

Plugins may change the parameters of this function depending on the value of the type parameter, see the IDatasetForm plugin interface.

Parameters:
  • name (string) – the name of the new dataset, must be between 2 and 100 characters long and contain only lowercase alphanumeric characters, - and _, e.g. 'warandpeace'
  • title (string) – the title of the dataset (optional, default: same as name)
  • author (string) – the name of the dataset’s author (optional)
  • author_email (string) – the email address of the dataset’s author (optional)
  • maintainer (string) – the name of the dataset’s maintainer (optional)
  • maintainer_email (string) – the email address of the dataset’s maintainer (optional)
  • license_id (license id string) – the id of the dataset’s license, see license_list() for available values (optional)
  • notes (string) – a description of the dataset (optional)
  • url (string) – a URL for the dataset’s source (optional)
  • version (string, no longer than 100 characters) – (optional)
  • state (string) – the current state of the dataset, e.g. 'active' or 'deleted', only active datasets show up in search results and other lists of datasets, this parameter will be ignored if you are not authorized to change the state of the dataset (optional, default: 'active')
  • type (string) – the type of the dataset (optional), IDatasetForm plugins associate themselves with different dataset types and provide custom dataset handling behaviour for these types
  • resources (list of resource dictionaries) – the dataset’s resources, see resource_create() for the format of resource dictionaries (optional)
  • tags (list of tag dictionaries) – the dataset’s tags, see tag_create() for the format of tag dictionaries (optional)
  • extras (list of dataset extra dictionaries) – the dataset’s extras (optional), extras are arbitrary (key: value) metadata items that can be added to datasets, each extra dictionary should have keys 'key' (a string), 'value' (a string), and optionally 'deleted'
  • relationships_as_object (list of relationship dictionaries) – see package_relationship_create() for the format of relationship dictionaries (optional)
  • relationships_as_subject (list of relationship dictionaries) – see package_relationship_create() for the format of relationship dictionaries (optional)
  • groups (list of dictionaries) – the groups to which the dataset belongs (optional), each group dictionary should have one or more of the following keys which identify an existing group: 'id' (the id of the group, string), 'name' (the name of the group, string), 'title' (the title of the group, string), to see which groups exist call group_list()
Returns:

the newly created dataset (unless ‘return_id_only’ is set to True in the context, in which case just the dataset id will be returned)

Return type:

dictionary

ckan.logic.action.create.resource_create(context, data_dict)

Appends a new resource to a datasets list of resources.

Parameters:
  • package_id (string) – id of package that the resource needs should be added to.
  • url (string) – url of resource
  • revision_id – (optional)
  • description (string) – (optional)
  • format (string) – (optional)
  • hash (string) – (optional)
  • name (string) – (optional)
  • resource_type (string) – (optional)
  • mimetype (string) – (optional)
  • mimetype_inner (string) – (optional)
  • webstore_url (string) – (optional)
  • cache_url (string) – (optional)
  • size (int) – (optional)
  • created (iso date string) – (optional)
  • last_modified (iso date string) – (optional)
  • cache_last_updated (iso date string) – (optional)
  • webstore_last_updated (iso date string) – (optional)
Returns:

the newly created resource

Return type:

dictionary

ckan.logic.action.create.related_create(context, data_dict)

Add a new related item to a dataset.

You must provide your API key in the Authorization header.

Parameters:
  • title (string) – the title of the related item
  • type (string) – the type of the related item, e.g. 'Application', 'Idea' or 'Visualisation'
  • id (string) – the id of the related item (optional)
  • description (string) – the description of the related item (optional)
  • url (string) – the URL to the related item (optional)
  • image_url (string) – the URL to the image for the related item (optional)
  • dataset_id (string) – the name or id of the dataset that the related item belongs to (optional)
Returns:

the newly created related item

Return type:

dictionary

ckan.logic.action.create.package_relationship_create(context, data_dict)

Create a relationship between two datasets (packages).

You must be authorized to edit both the subject and the object datasets.

Parameters:
  • subject (string) – the id or name of the dataset that is the subject of the relationship
  • object – the id or name of the dataset that is the object of the relationship
  • type (string) – the type of the relationship, one of 'depends_on', 'dependency_of', 'derives_from', 'has_derivation', 'links_to', 'linked_from', 'child_of' or 'parent_of'
  • comment (string) – a comment about the relationship (optional)
Returns:

the newly created package relationship

Return type:

dictionary

ckan.logic.action.create.member_create(context, data_dict=None)

Make an object (e.g. a user, dataset or group) a member of a group.

If the object is already a member of the group then the capacity of the membership will be updated.

You must be authorized to edit the group.

Parameters:
  • id (string) – the id or name of the group to add the object to
  • object (string) – the id or name of the object to add
  • object_type (string) – the type of the object being added, e.g. 'package' or 'user'
  • capacity (string) – the capacity of the membership
Returns:

the newly created (or updated) membership

Return type:

dictionary

ckan.logic.action.create.group_create(context, data_dict)

Create a new group.

You must be authorized to create groups.

Plugins may change the parameters of this function depending on the value of the type parameter, see the IGroupForm plugin interface.

Parameters:
  • name (string) – the name of the group, a string between 2 and 100 characters long, containing only lowercase alphanumeric characters, - and _
  • id (string) – the id of the group (optional)
  • title (string) – the title of the group (optional)
  • description (string) – the description of the group (optional)
  • image_url (string) – the URL to an image to be displayed on the group’s page (optional)
  • type (string) – the type of the group (optional), IGroupForm plugins associate themselves with different group types and provide custom group handling behaviour for these types Cannot be ‘organization’
  • state (string) – the current state of the group, e.g. 'active' or 'deleted', only active groups show up in search results and other lists of groups, this parameter will be ignored if you are not authorized to change the state of the group (optional, default: 'active')
  • approval_status (string) – (optional)
  • extras (list of dataset extra dictionaries) – the group’s extras (optional), extras are arbitrary (key: value) metadata items that can be added to groups, each extra dictionary should have keys 'key' (a string), 'value' (a string), and optionally 'deleted'
  • packages (list of dictionaries) – the datasets (packages) that belong to the group, a list of dictionaries each with keys 'name' (string, the id or name of the dataset) and optionally 'title' (string, the title of the dataset)
  • groups (list of dictionaries) – the groups that belong to the group, a list of dictionaries each with key 'name' (string, the id or name of the group) and optionally 'capacity' (string, the capacity in which the group is a member of the group)
  • users (list of dictionaries) – the users that belong to the group, a list of dictionaries each with key 'name' (string, the id or name of the user) and optionally 'capacity' (string, the capacity in which the user is a member of the group)
Returns:

the newly created group

Return type:

dictionary

ckan.logic.action.create.organization_create(context, data_dict)

Create a new organization.

You must be authorized to create organizations.

Plugins may change the parameters of this function depending on the value of the type parameter, see the IGroupForm plugin interface.

Parameters:
  • name (string) – the name of the organization, a string between 2 and 100 characters long, containing only lowercase alphanumeric characters, - and _
  • id (string) – the id of the organization (optional)
  • title (string) – the title of the organization (optional)
  • description (string) – the description of the organization (optional)
  • image_url (string) – the URL to an image to be displayed on the organization’s page (optional)
  • state (string) – the current state of the organization, e.g. 'active' or 'deleted', only active organizations show up in search results and other lists of organizations, this parameter will be ignored if you are not authorized to change the state of the organization (optional, default: 'active')
  • approval_status (string) – (optional)
  • extras (list of dataset extra dictionaries) – the organization’s extras (optional), extras are arbitrary (key: value) metadata items that can be added to organizations, each extra dictionary should have keys 'key' (a string), 'value' (a string), and optionally 'deleted'
  • packages (list of dictionaries) – the datasets (packages) that belong to the organization, a list of dictionaries each with keys 'name' (string, the id or name of the dataset) and optionally 'title' (string, the title of the dataset)
  • users (list of dictionaries) – the users that belong to the organization, a list of dictionaries each with key 'name' (string, the id or name of the user) and optionally 'capacity' (string, the capacity in which the user is a member of the organization)
Returns:

the newly created organization

Return type:

dictionary

ckan.logic.action.create.rating_create(context, data_dict)

Rate a dataset (package).

You must provide your API key in the Authorization header.

Parameters:
  • package (string) – the name or id of the dataset to rate
  • rating (int) – the rating to give to the dataset, an integer between 1 and 5
Returns:

a dictionary with two keys: 'rating average' (the average rating of the dataset you rated) and 'rating count' (the number of times the dataset has been rated)

Return type:

dictionary

ckan.logic.action.create.user_create(context, data_dict)

Create a new user.

You must be authorized to create users.

Parameters:
  • name (string) – the name of the new user, a string between 2 and 100 characters in length, containing only lowercase alphanumeric characters, - and _
  • email (string) – the email address for the new user
  • password (string) – the password of the new user, a string of at least 4 characters
  • id (string) – the id of the new user (optional)
  • fullname (string) – the full name of the new user (optional)
  • about (string) – a description of the new user (optional)
  • openid (string) – (optional)
Returns:

the newly created yser

Return type:

dictionary

ckan.logic.action.create.vocabulary_create(context, data_dict)

Create a new tag vocabulary.

You must be a sysadmin to create vocabularies.

Parameters:
  • name (string) – the name of the new vocabulary, e.g. 'Genre'
  • tags (list of tag dictionaries) – the new tags to add to the new vocabulary, for the format of tag dictionaries see tag_create()
Returns:

the newly-created vocabulary

Return type:

dictionary

ckan.logic.action.create.activity_create(context, activity_dict, ignore_auth=False)

Create a new activity stream activity.

You must be a sysadmin to create new activities.

Parameters:
  • user_id (string) – the name or id of the user who carried out the activity, e.g. 'seanh'
  • object_id – the name or id of the object of the activity, e.g. 'my_dataset'
  • activity_type (string) – the type of the activity, this must be an activity type that CKAN knows how to render, e.g. 'new package', 'changed user', 'deleted group' etc. (for a full list see activity_renderers in ckan/logic/action/get.py
  • data (dictionary) – any additional data about the activity
Returns:

the newly created activity

Return type:

dictionary

ckan.logic.action.create.tag_create(context, tag_dict)

Create a new vocabulary tag.

You must be a sysadmin to create vocabulary tags.

You can only use this function to create tags that belong to a vocabulary, not to create free tags. (To create a new free tag simply add the tag to a package, e.g. using the package_update function.)

Parameters:
  • name (string) – the name for the new tag, a string between 2 and 100 characters long containing only alphanumeric characters and -, _ and ., e.g. 'Jazz'
  • vocabulary_id (string) – the name or id of the vocabulary that the new tag should be added to, e.g. 'Genre'
Returns:

the newly-created tag

Return type:

dictionary

ckan.logic.action.create.follow_user(context, data_dict)

Start following another user.

You must provide your API key in the Authorization header.

Parameters:id (string) – the id or name of the user to follow, e.g. 'joeuser'
Returns:a representation of the ‘follower’ relationship between yourself and the other user
Return type:dictionary
ckan.logic.action.create.follow_dataset(context, data_dict)

Start following a dataset.

You must provide your API key in the Authorization header.

Parameters:id (string) – the id or name of the dataset to follow, e.g. 'warandpeace'
Returns:a representation of the ‘follower’ relationship between yourself and the dataset
Return type:dictionary
ckan.logic.action.create.follow_group(context, data_dict)

Start following a group.

You must provide your API key in the Authorization header.

Parameters:id (string) – the id or name of the group to follow, e.g. 'roger'
Returns:a representation of the ‘follower’ relationship between yourself and the group
Return type:dictionary