datagovsg.ckan

Client for interacting with the CKAN APIs.

Example usage:

# list all available packages
from datagovsg import Ckan
ckan = Ckan()
packages = ckan.package_list()

Methods

class datagovsg.ckan.client.Client

Bases: datagovsg.client.__Client

Interact with CKAN software to access its catalogue of datasets.

Search data in a resource.

Parameters
  • resource_id (str) – ID or alias of the resource to be searched against.

  • limit (int) – (optional) Maximum number of rows to return. Default: 100.

  • offset (int) – (optional) Offset this number of rows. Default: 0.

  • fields (str) – (optional) Fields to return.

  • filters (dict) – (optional) Dictionary of matching conditions, e.g {“key1”: “a”, “key2”: “b”}.

  • q (str or dict) – (optional) Full text query. If it’s a string, it’ll search on all fields on each row. If it’s a dictionary as {“key1”: “a”, “key2”: “b”}, it’ll search on each specific field.

  • sort (str) – (optional) Comma-separated field names with ordering, e.g. “fieldname1, fieldname2 desc”.

  • records_format (str) – (optional) The format for the records return value. “objects”: list of {fieldname1: value1, …} dicts “lists”: list of [value1, value2, …] lists “csv”: comma-separated values with no header “tsv”: tab-separated values with no header Default: “objects”.

Returns

(dict) Resources that match the search criteria. All of the records are concatenated together, so there is no need for further pagination.

References

https://data.gov.sg/dataset/ckan-datastore-search

package_list(limit=None, offset=None)

Return a list of datasets on data.gov.sg.

Parameters
  • limit (int) – (optional) Maximum number of packages to return per page. Default: None, i.e. return all packages.

  • offset (int) – (optional) Offset this number of packages.

Returns

(dict) Metadata and list of packages.

References

https://data.gov.sg/dataset/ckan-package-list

package_show(package_id)

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

Parameters

package_id (str) – ID or name of the dataset.

Returns

(dict) Metadata and resources of the requested package.

References

https://data.gov.sg/dataset/ckan-package-show

resource_show(resource_id)

Return the metadata of a resource.

Parameters

resource_id (str) – ID of the resource.

Returns

(dict) Metadata of the requested resource.

References

https://data.gov.sg/dataset/ckan-resource-show