DataCommonsToolkit
- Executing SPARQL queries
- Retrieving triples associated with nodes
- Fetching statistical time series data
- Analyzing property labels and values
- Retrieving places within a given place type
- Obtaining statistical values for specific variables and locations
init
- timeout (Optional[float], optional): Maximum time in seconds to wait for API calls to complete. If None, will wait indefinitely. (default: :obj:
None
)
query_data_commons
- query_string (str): A SPARQL query string.
None
) otherwise.
Note:
- Only supports a limited subset of SPARQL functionality (ORDER BY, DISTINCT, LIMIT).
- Each variable in the query should have a ‘typeOf’ condition.
- The Python SPARQL library currently only supports the V1 version of the API.
get_triples
- dcids (Union[str, List[str]]): A single DCID or a list of DCIDs to query.
- limit (int): The maximum number of triples per combination of property and type. (default: :obj:
500
)
None
) otherwise.
Note:
- The function will raise a ValueError if any of the required arguments are missing.
- The function will raise a TypeError if the dcids are not a string or a list of strings.
- The function will raise a ValueError if the limit is not between 1 and 500.
- The function will raise a KeyError if one or more of the provided DCIDs do not exist in the Data Commons knowledge graph.
- The function will raise an Exception if an unexpected error occurs.
get_stat_time_series
- place (str): The dcid of the Place to query for.
- stat_var (str): The dcid of the StatisticalVariable.
- measurement_method (str, optional): The technique used for measuring a statistical variable. (default: :obj:
None
) - observation_period (str, optional): The time period over which an observation is made. (default: :obj:
None
) - scaling_factor (str, optional): Property of statistical variables indicating factor by which a measurement is multiplied to fit a certain format. (default: :obj:
None
) - unit (str, optional): The unit of measurement. (default: :obj:
None
)
None
) otherwise.
Reference:
https://docs.datacommons.org/api/python/stat_series.html
get_property_labels
- dcids (list): A list of Data Commons IDs (DCIDs) to analyze.
- out (bool): Direction of properties to retrieve. (default: :obj:
True
)
None
) otherwise.
Reference:
https://docs.datacommons.org/api/python/property_label.html
get_property_values
- dcids (list): A list of Data Commons IDs (DCIDs) to analyze.
- prop (str): The property to analyze.
- value_type (str, optional): The type of the property value to filter by. Defaults to NONE. Only applicable if the value refers to a node.
- out (bool, optional): The label’s direction. (default: :obj:
True
) (only returning response nodes directed towards the requested node). If set to False, will only return response nodes directed away from the request node. (default: :obj:None
) (default: True) - limit (int, optional): (≤ 500) Maximum number of values returned per node. (default: :obj:
datacommons.utils._MAX_LIMIT
)
None
) otherwise.
Reference:
https://docs.datacommons.org/api/python/property_value.html
get_places_in
- dcids (list): A list of Data Commons IDs (DCIDs) to analyze.
- place_type (str): The type of the place to filter by.
None
) otherwise.
Reference:
https://docs.datacommons.org/api/python/place_in.html
get_stat_value
- place (str): The DCID of the Place to query for.
- stat_var (str): The DCID of the StatisticalVariable.
- date (str, optional): The preferred date of observation in ISO 8601 format. If not specified, returns the latest observation. (default: :obj:
None
) - measurement_method (str, optional): The DCID of the preferred measurementMethod value. (default: :obj:
None
) - observation_period (str, optional): The preferred observationPeriod value. (default: :obj:
None
) - unit (str, optional): The DCID of the preferred unit value. (default: :obj:
None
) - scaling_factor (str, optional): The preferred scalingFactor value. (default: :obj:
None
)
None
)
otherwise.
Reference:
https://docs.datacommons.org/api/python/stat_value.html
get_stat_all
- places (str): The DCID IDs of the Place objects to query for. (Here DCID stands for Data Commons ID, the unique identifier assigned to all entities in Data Commons.)
- stat_vars (str): The dcids of the StatisticalVariables at
- https: //datacommons.org/browser/StatisticalVariable
None
) otherwise.
Reference:
https://docs.datacommons.org/api/python/stat_all.html