nrgpy.cloud_api.auth module#

class nrgpy.cloud_api.auth.CloudApi(client_id: str = '', client_secret: str = '', url_base: str = 'https://cloud-api.nrgsystems.com/nrgcloudcustomerapi/')[source]#

Bases: object

Parent class for NRG Cloud API functionality

nrgpy simplifies usage of the NRG Cloud APIs. See the documentation for the cloud_api.sites, .export, and .convert modules for more information.

For non-nrgpy implementations, the following Usage information may be helpful.

The base url for the NRG Cloud APIs is

https://cloud-api.nrgsystems.com/nrgcloudcustomerapi/

Use client ID and secret to obtain a bearer token at the /token endpoint. This token is good for 24 hours.

You will be limited to creating 10 tokens per day, though normally one token should suffice, so please cache. nrgpy’s cloud_api modules will automatically manage bearer tokens, refreshing only when necessary.

Endpoints:

base

https://cloud-api.nrgsystems.com/nrgcloudcustomerapi/

/token

for accessing bearer token. Client ID and Secret required.

/sites

Get list of sites. Bearer token required

/convert

Convert RLD file to TXT. Bearer token required

/export

Export TXT or RLD files for a given date range. NEC files may be used to format TXT outputs. Bearer token required.

load_token() None[source]#

read session token from pickle file

maintain_session_token() None[source]#

maintain a current/valid session token for data service api

prepare_file_bytes(filename: str = '') bytes[source]#
request_session_token() None[source]#

Generates a new session token for convert service api

Requires an active account with NRG Cloud. To sign up for a free account, go to:

https://cloud.nrgsystems.com

Client ID and Secret can be accessed here:

https://cloud.nrgsystems.com/data-manager/api-setup

Parameters:
client_idstr

obtained from NRG Systems

client_secretstr
Returns:
session_tokenstr

valid for 24 hour

session_start_timedatetime

start time of 24 hour countdown

save_token() None[source]#

save session token in token pickle file

token_valid() bool[source]#

check if token is still valid

Parameters:
session_start_timedatetime

generated at time of token request

Returns:
statusbool

true if still valid, false if expired

nrgpy.cloud_api.auth.cloud_api#

alias of CloudApi

nrgpy.cloud_api.auth.is_authorized(resp) bool[source]#