bea package

Submodules

bea.api module

This module contains specifics based on the current documentation, to make calls and consume the data released by the BEA.

Although the BEA (at the time of this writing) supports both XML and JSON responses; this module does not have XML response support at this time, only JSON and Python types.

API Calling Limits

The API has default calling limits as shown below. These limits are meant to protect BEA’s API and webserver infrastructure from activity that may be detrimental to that infrastructure and/or unfairly impede other API users.

  • 1000 API calls per minute, and/or
  • 30 errors per minute, and/or
  • 50 MB (raw data) per minute.

Any user that exceeds the above calling limits will receive an explanatory error message for each API call until the per-minute cause has expired. The best way to avoid such errors is to design your application to call the API within these limits, e.g., programmatically regulate the frequency/size of API calls.

class bea.api.BaseHandler(user_key, result_format='JSON')[source]

Bases: object

This is the super class handler with attributes common to all subclassed handlers for BEA requests

_get_and_process_response(url, target_node, echo_request=False)[source]

Takes the request URL and a target node, delegating to a few other helper methods to unpack and process the response.

Parameters:
  • url (str) – The target request URL
  • target_node (str) – The response node containing the data
  • echo_request (bool) – Whether to echo the request (params, etc.) in the response.
Returns:

The targeted data results as JSON

Return type:

JSON

_traverse_nodes(response, node_hierarchy)[source]
Parameters:
  • response
  • node_hierarchy
Returns:

Return type:

_unpack_request(response)[source]

Caller to unpack the request node hierarchy, i.e. NOT the results node hierarchy. Delegates to other helper methods.

Parameters:response (JSON response) – The JSON response
Returns:JSON response’s request
Return type:
_unpack_results(response, target_node)[source]
Parameters:
  • response
  • target_node
Returns:

Return type:

class bea.api.DataHandler(user_key, result_format='JSON')[source]

Bases: bea.api.BaseHandler

get_data(dataset_name, **params)[source]
Parameters:
  • dataset_name
  • params
Returns:

Return type:

class bea.api.MetadataHandler(user_key, result_format='JSON')[source]

Bases: bea.api.BaseHandler

create_metadata_dict(dataset_name)[source]
Parameters:dataset_name
Returns:
Return type:
get_dataset_list(target_node='Dataset', echo_request=False)[source]

Retrieves the BEA datasets list

Parameters:
  • target_node (str) – The dataset target node
  • echo_request (bool) – Whether to echo the request and params in the response
Returns:

The targeted data results as JSON

Return type:

JSON

get_param_list(dataset_name, target_node='Parameter', echo_request=False)[source]
Parameters:
  • dataset_name
  • target_node
  • echo_request
Returns:

Return type:

get_param_values(dataset_name, param_name, target_node='ParamValue', echo_request=False)[source]
Parameters:
  • dataset_name
  • param_name
  • target_node
  • echo_request
Returns:

Return type:

get_param_values_filtered(dataset_name, target_param, table_name, target_node='ParamValue', echo_request=False)[source]
Parameters:
  • dataset_name
  • target_param
  • table_name
  • target_node
  • echo_request
Returns:

Return type:

Module contents