solarforecastarbiter.io.api.APISession¶
-
class
solarforecastarbiter.io.api.
APISession
(access_token, default_timeout=(10, 60), base_url=None)[source]¶ Subclass of requests.Session to handle requets to the SolarForecastArbiter API. The Session provides connection pooling, automatic retries for certain types of requets, default timeouts, and a default base url. Responses are converted into the appropriate class from datamodel.py or a pandas object.
Parameters: - access_token (string or HiddenToken) – The base64 encoded Bearer token to authenticate with the API
- default_timeout (float or tuple, optional) – A default timeout to add to all requests. If a tuple, the first element is the connection timeout and the second is the read timeout. Default is 10 seconds for connection and 60 seconds to read from the server.
- base_url (string) – URL to use as the base for endpoints to APISession
Notes
To pass the API calls through a proxy server, set either the HTTP_PROXY or HTTPS_PROXY environment variable. If necessary, you can also specify a SSL certificate using the REQUESTS_CA_BUNDLE environment variable. For example, on a Linux machine:
>>> export HTTPS_PROXY=https://some_corporate_proxy.com:8080 >>> export REQUESTS_CA_BUNDLE=/path/to/certificates/cert.crt >>> python script_that_calls_api.py
For more information, see the “Advanced Usage” documentation for the requests package: https://requests.readthedocs.io/en/master/user/advanced/
-
__init__
(access_token, default_timeout=(10, 60), base_url=None)[source]¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
(access_token[, default_timeout, …])Initialize self. chunk_value_requests
(api_path, start, end, …)Breaks up a get requests for values into multiple requests limited by the request_limit argument. close
()Closes all adapters and as such the session create_aggregate
(aggregate)Create a new aggregate in the API with the given Aggregate model create_forecast
(forecast)Create a new forecast in the API with the given Forecast model create_observation
(observation)Create a new observation in the API with the given Observation model create_probabilistic_forecast
(forecast)Create a new forecast in the API with the given ProbabilisticForecast model create_report
(report)Post the report request to the API. create_site
(site)Create a new site in the API with the given Site model delete
(url, **kwargs)Sends a DELETE request. get
(url, **kwargs)Sends a GET request. get_adapter
(url)Returns the appropriate connection adapter for the given URL. get_aggregate
(aggregate_id)Get Aggregate metadata from the API for the given aggregate_id get_aggregate_values
(aggregate_id, start, end)Get aggregate values from start to end for aggregate_id from the API get_forecast
(forecast_id)Get Forecast metadata from the API for the given forecast_id get_forecast_time_range
(forecast_id)Get the miniumum and maximum timestamps for forecast values. get_forecast_value_gaps
(forecast_id, start, end)Get any gaps in forecast data from start to end. get_forecast_values
(forecast_id, start, end)Get forecast values from start to end for forecast_id get_observation
(observation_id)Get the metadata from the API for the a given observation_id in an Observation object. get_observation_time_range
(observation_id)Get the minimum and maximum timestamps for observation values. get_observation_value_gaps
(observation_id, …)Get any gaps in observation data from start to end. get_observation_values
(observation_id, …)Get observation values from start to end for observation_id from the API get_observation_values_not_flagged
(…[, …])Get the dates where the observation series is NOT flagged with the given flag/bitmask. get_probabilistic_forecast
(forecast_id)Get ProbabilisticForecast metadata from the API for the given forecast_id. get_probabilistic_forecast_constant_value
(…)Get ProbabilisticForecastConstantValue metadata from the API for the given forecast_id. get_probabilistic_forecast_constant_value_time_range
(…)Get the miniumum and maximum timestamps for forecast values. get_probabilistic_forecast_constant_value_value_gaps
(…)Get any gaps in forecast data from start to end. get_probabilistic_forecast_constant_value_values
(…)Get forecast values from start to end for forecast_id get_probabilistic_forecast_value_gaps
(…)Get any gaps in forecast data from start to end. get_probabilistic_forecast_values
(…[, …])Get all probabilistic forecast values for each from start to end for forecast_id get_raw_report_processed_data
(report_id, …)Load the processed forecast/observation data into the datamodel.ProcessedForecastObservation objects of the raw_report. get_redirect_target
(resp)Receives a Response. get_report
(report_id)Get the metadata, and possible raw report if it has processed, from the API for the given report_id in a Report object. get_site
(site_id)Retrieve site metadata for site_id from the API and process into the proper model. get_user_info
()Get information about the current user from the API get_value_gaps
(obj, start, end)Get gaps in the time series values from start to end for object from the API. get_values
(obj, start, end[, …])Get time series values from start to end for object from the API head
(url, **kwargs)Sends a HEAD request. list_aggregates
()List all Aggregates a user has access to. list_forecasts
()List all Forecasts a user has access to. list_observations
()List the observations a user has access to. list_probabilistic_forecasts
()List all ProbabilisticForecasts a user has access to. list_reports
()List the reports a user has access to. list_sites
()List all the sites available to a user. list_sites_in_zone
(zone)List all the sites available to a user in the given climate zone. merge_environment_settings
(url, proxies, …)Check the environment and merge it with some settings. mount
(prefix, adapter)Registers a connection adapter to a prefix. options
(url, **kwargs)Sends a OPTIONS request. patch
(url[, data])Sends a PATCH request. post
(url[, data, json])Sends a POST request. post_forecast_values
(forecast_id, …)Upload the given forecast values to the appropriate forecast_id of the API post_observation_values
(observation_id, …)Upload the given observation values to the appropriate observation_id of the API. post_probabilistic_forecast_constant_value_values
(…)Upload the given forecast values to the appropriate forecast_id of the API post_raw_report
(report_id, raw_report[, status])Update the report with the raw report and metrics post_raw_report_processed_data
(report_id, …)Post the processed data that was used to make the report to the API. prepare_request
(request)Constructs a PreparedRequest
for transmission and returns it.process_report_dict
(rep_dict)Load parameters from rep_dict into a Report object, getting forecasts and observations as necessary put
(url[, data])Sends a PUT request. rebuild_auth
(prepared_request, response)When being redirected we may want to strip authentication from the request to avoid leaking credentials. rebuild_method
(prepared_request, response)When being redirected we may want to change the method of the request based on certain specs or browser behavior. rebuild_proxies
(prepared_request, proxies)This method re-evaluates the proxy configuration by considering the environment variables. request
(method, url, *args, **kwargs)Modify the default Session.request to add in the default timeout and make requests relative to the base_url. resolve_redirects
(resp, req[, stream, …])Receives a Response. search_climatezones
(latitude, longitude)Find all climate zones that the location is in. send
(request, **kwargs)Send a given PreparedRequest. should_strip_auth
(old_url, new_url)Decide whether Authorization header should be removed when redirecting update_report_status
(report_id, status)Update the status of the report