singstat.client¶
Client for interacting with the SingStat API endpoints.
Example usage:
# search for a resource ID
from singstat import Client
client = Client()
resources = client.resource_id(keyword="population", search_option="all")
Methods¶
- class singstat.client.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 response’s
Data.recordslist has 0 items.- Returns:
Metadata of the requested resource.
- Return type:
- resource_id(**kwargs: Unpack[ResourceIdArgsDict]) ResourceIdDict¶
Search for a list of resources.
- Parameters:
kwargs (ResourceIdArgsDict) – Key-value arguments to be passed as parameters to the endpoint URL.
- Raises:
APIError –
search_optionis not"all","title"or"variable".- Warns RuntimeWarning:
“Empty data set returned” when response’s
Data.totalis 0.- Returns:
List of resources.
- Return type:
- tabledata(resource_id: str, **kwargs: Unpack[TabledataArgsDict]) 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.
- 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 response’s
Data.rowlist has 0 items.- Returns:
Records of data that match the search criteria.
- Return type: