singstat.client Client

Client for interacting with the SingStat API endpoints.

Example usage:

# list all available packages
from singstat import Client
client = Client()
resources = client.resource_id()

Methods

class singstat.client.Client(cache_backend: str | BaseCache = 'sqlite', is_test_api: bool = False)

Bases: SingStat

Interact with SingStat’s API to access its catalogue of datasets.

References: https://tablebuilder.singstat.gov.sg/view-api/for-developers

Parameters:
  • cache_backend (str | BaseCache)

  • is_test_api (bool)

metadata(resource_id: str) MetadataDict

Return the metadata of a resource.

Parameters:

resource_id (str) – ID of the resource.

Warns RuntimeWarning:

“Empty data set returned” when data_count is 1 but data.records is empty.

Returns:

Metadata of the requested resource.

Return type:

MetadataDict

resource_id(**kwargs: Any) ResourceIdDict

Search for a list of resources.

Parameters:

kwargs (ResourceIdArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL. Refer to ResourceIdArgsDict for the specification of the argument names and types.

Raises:

APIErrorsearch_option is not “all”, “title” or “variable”.

Warns RuntimeWarning:

“Empty data set returned” when data_count is 1 but data.total is 0.

Returns:

List of resources.

Return type:

ResourceIdDict

tabledata(resource_id: str, **kwargs: Any) TabledataDict

Retrieve data in a resource.

Parameters:
  • resource_id (str) – ID of the resource.

  • kwargs (TabledataArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL. Refer to TabledataArgsDict for the specification of the argument names and types.

Raises:
  • APIErrorbetween tuple has at least one value that is less than 0.

  • APIErrorbetween tuple’s first value is greater than its second value.

  • APIErrorlimit is not between 0 and 3000.

  • APIErroroffset is less than 0.

  • APIErrorsort_by does not match the regular expression r'^(key|value|seriesNo|rowNo|rowText) (asc|desc)$'.

Warns RuntimeWarning:

“Empty data set returned” when data_count is 1 but data.row is empty.

Returns:

Records of data that match the search criteria.

Return type:

TabledataDict