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:
SingStatInteract with SingStat’s API to access its catalogue of datasets.
References: https://tablebuilder.singstat.gov.sg/view-api/for-developers
- 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_countis 1 butdata.recordsis empty.- Returns:
Metadata of the requested resource.
- Return type:
- 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
ResourceIdArgsDictfor the specification of the argument names and types.- Raises:
APIError –
search_optionis not “all”, “title” or “variable”.- Warns RuntimeWarning:
“Empty data set returned” when
data_countis 1 butdata.totalis 0.- Returns:
List of resources.
- Return type:
- 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
TabledataArgsDictfor the specification of the argument names and types.
- Raises:
APIError –
betweentuple has at least one value that is less than 0.APIError –
betweentuple’s first value is greater than its second value.APIError –
limitis not between 0 and 3000.APIError –
offsetis less than 0.APIError –
sort_bydoes not match the regular expressionr'^(key|value|seriesNo|rowNo|rowText) (asc|desc)$'.
- Warns RuntimeWarning:
“Empty data set returned” when
data_countis 1 butdata.rowis empty.- Returns:
Records of data that match the search criteria.
- Return type: