gmn_python_api.gmn_rest_api#

This module contains functions to read data from the GMN REST API. The REST API uses the Datasette API endpoint. More info: https://gmn-python-api.readthedocs.io/en/latest/rest_api.html

Module Contents#

Functions#

get_meteor_summary_data_all([where, having, order_by, ...])

Get all meteor summary data from the Meteor Summary GMN REST API endpoint.

get_meteor_summary_data_iter([where, having, order_by])

An iterator for fetching meteor summary data from the Meteor Summary GMN REST API

get_meteor_summary_data([where, having, order_by])

Get meteor summary data from the Meteor Summary GMN REST API endpoint starting from

get_data(sql)

Get data from the General GMN REST API endpoint using a custom SQL query.

get_data_from_url(query_url)

Get data from a specified GMN REST API endpoint URL.

_http_get_response(url)

Perform an HTTP GET request and return the response.

Attributes#

gmn_python_api.gmn_rest_api.GMN_REST_API_DOMAIN = 'https://explore.globalmeteornetwork.org'#
gmn_python_api.gmn_rest_api.QUERY_URL#
gmn_python_api.gmn_rest_api.METEOR_SUMMARY_QUERY_URL#
exception gmn_python_api.gmn_rest_api.LastModifiedError#

Bases: Exception

Raised when the data has modified since the last request.

gmn_python_api.gmn_rest_api.get_meteor_summary_data_all(where=None, having=None, order_by=None, last_modified_error_retries=3)#

Get all meteor summary data from the Meteor Summary GMN REST API endpoint.

Parameters:
  • where (Optional[str]) – Optional parameter to filter data via a SQL WHERE clause e.g. meteor.unique_trajectory_identifier = ‘20190103131723_6dnE3’.

  • having (Optional[str]) – Optional parameter to filter data via a SQL HAVING clause e.g. participating_stations LIKE ‘%US0003%’.

  • order_by (Optional[str]) – Optional parameter to specify the order of results via a SQL ORDER BY clause e.g. meteor.unique_trajectory_identifier DESC.

  • last_modified_error_retries (int) – Number of times to retry if the data has modified since the last request.

Raises:

LastModifiedError: If the data has modified since the last request too many times.

Raises:

requests.exceptions.HTTPError: If the HTTP response status code is not 200 OK.

Returns:

A list of json data.

Return type:

List[Dict[str, Any]]

gmn_python_api.gmn_rest_api.get_meteor_summary_data_iter(where=None, having=None, order_by=None)#
An iterator for fetching meteor summary data from the Meteor Summary GMN REST API

endpoint in pages. This is useful for processing large amounts of data. The data is returned in pages of 1000 rows.

Parameters:
  • where (Optional[str]) – Optional parameter to filter data via a SQL WHERE clause e.g. meteor.unique_trajectory_identifier = ‘20190103131723_6dnE3’.

  • having (Optional[str]) – Optional parameter to filter data via a SQL HAVING clause e.g. participating_stations LIKE ‘%US0003%’.

  • order_by (Optional[str]) – Optional parameter to specify the order of results via a SQL ORDER BY clause e.g. meteor.unique_trajectory_identifier DESC.

Raises:

requests.exceptions.HTTPError: If the HTTP response status code is not 200 OK.

Raises:

LastModifiedError: If the data has modified since the last request.

Raises:

requests.exceptions.HTTPError: If the HTTP response status code is not 200 OK.

Returns:

An iterable of json data.

Return type:

Iterable[List[Dict[str, Any]]]

gmn_python_api.gmn_rest_api.get_meteor_summary_data(where=None, having=None, order_by=None)#
Get meteor summary data from the Meteor Summary GMN REST API endpoint starting from

the first page.

Parameters:
  • where (Optional[str]) – Optional parameter to filter data via a SQL WHERE clause e.g. meteor.unique_trajectory_identifier = ‘20190103131723_6dnE3’.

  • having (Optional[str]) – Optional parameter to filter data via a SQL HAVING clause e.g. participating_stations LIKE ‘%US0003%’.

  • order_by (Optional[str]) – Optional parameter to specify the order of results via a SQL ORDER BY clause e.g. meteor.unique_trajectory_identifier DESC.

Raises:

requests.exceptions.HTTPError: If the HTTP response status code is not 200 OK.

Returns:

Tuple of json data, next URL for pagination, and the last modified date of the GMN data store. If iterating through pages, last_modified should be checked against the last_modified of the previous page. If they are different, then the data has modified since the last request, and the pagination is invalid.

Return type:

Tuple[List[Dict[str, Any]], Optional[str], Optional[str]]

gmn_python_api.gmn_rest_api.get_data(sql)#

Get data from the General GMN REST API endpoint using a custom SQL query.

Parameters:

sql (str) – SQL query to execute (read-only).

Raises:

requests.exceptions.HTTPError: If the HTTP response status code is not 200 OK.

Returns:

Tuple containing a list of dictionaries containing meteor trajectory data and the last modified date of the GMN data store. If iterating through pages, last_modified should be checked against the last_modified of the previous page. If they are different, then the data has modified since the last request, and the pagination is invalid.

Return type:

Tuple[List[Dict[str, Any]], Optional[str]]

gmn_python_api.gmn_rest_api.get_data_from_url(query_url)#

Get data from a specified GMN REST API endpoint URL.

Parameters:

query_url (str) – URL for querying data from the GMN REST API.

Raises:

requests.exceptions.HTTPError: If the HTTP response status code is not 200 OK.

Returns:

Tuple of json data, next URL for pagination, and the last modified date of the GMN data store. If iterating through pages, last_modified should be checked against the last_modified of the previous page. If they are different, then the data has modified since the last request, and the pagination is invalid.

Return type:

Tuple[List[Dict[str, Any]], Optional[str], Optional[str]]

gmn_python_api.gmn_rest_api._http_get_response(url)#

Perform an HTTP GET request and return the response.

Parameters:

url (str) – URL for the HTTP GET request.

Raises:

requests.exceptions.HTTPError: If the HTTP response status code is not 200 OK.

Returns:

Tuple containing the response text, the next URL for pagination, and the last modified date of the GMN data store.

Return type:

Tuple[str, Optional[str], Optional[str]]