h2integrate.resource.utilities.nlr_developer_api_keys#

Functions

get_nlr_developer_api_email([env_path])

Load the API email (NLR_API_EMAIL).

get_nlr_developer_api_key([env_path])

Load the API key (NLR_API_KEY).

load_file_with_variables(fpath[, variables])

Load environment variables from a text file.

set_developer_nlr_gov_email(email)

Set email as the global variable developer_nlr_gov_email.

set_developer_nlr_gov_key(key)

Set key as the global variable developer_nlr_gov_key.

set_nlr_key_dot_env([path])

Sets the environment variables NLR_API_EMAIL and NLR_API_KEY from a .env file.

h2integrate.resource.utilities.nlr_developer_api_keys._get_env_with_fallback(new_name, old_name)#

Get an environment variable by its new name, falling back to the deprecated old name.

If only the old name is set, a deprecation warning is issued.

Parameters:
  • new_name (str) – The new (preferred) environment variable name.

  • old_name (str) – The deprecated environment variable name.

Returns:

str | None – The value of the environment variable, or None if not set.

h2integrate.resource.utilities.nlr_developer_api_keys.set_developer_nlr_gov_key(key)#

Set key as the global variable developer_nlr_gov_key.

Parameters:

key (str) – API key for NLR Developer Network. Should be length 40.

h2integrate.resource.utilities.nlr_developer_api_keys.set_developer_nlr_gov_email(email)#

Set email as the global variable developer_nlr_gov_email.

Parameters:

email (str) – email corresponding to the API key for NLR Developer Network.

h2integrate.resource.utilities.nlr_developer_api_keys.load_file_with_variables(fpath, variables=['NLR_API_KEY', 'NLR_API_EMAIL'])#

Load environment variables from a text file.

Supports both the new NLR_API_* and the deprecated NREL_API_* variable names. If only the old names are found in the file a deprecation warning is emitted.

Parameters:
  • fpath (str | Path) – filepath to a text file with the extension ‘.env’ that may contain the environment variable(s) in variables.

  • variables (list | str, optional) – environment variable(s) to load from file. Defaults to [“NLR_API_KEY”, “NLR_API_EMAIL”].

Raises:

ValueError – If an environment variable is not found or found multiple times in the file.

h2integrate.resource.utilities.nlr_developer_api_keys.set_nlr_key_dot_env(path=None)#

Sets the environment variables NLR_API_EMAIL and NLR_API_KEY from a .env file.

Also supports the deprecated NREL_API_EMAIL and NREL_API_KEY variable names for backward compatibility (with deprecation warnings).

The following logic is used if path is input and exists:

  1. If the filename of the path is ‘.env’, load the environment variables using load_dotenv().

    Proceed to Step 3.

  2. If the filename of the path has an extension of ‘.env’ (such a filename of ‘my_env.env’),

    then load the environment variables using load_file_with_variables(). Proceed to step 3.

The following logic is used if path is not input or does not exist:

  1. check for possible locations of the ‘.env’ file. Searches the current working directory,

    the ROOT_DIR, and the parent of the ROOT_DIR. If the ‘.env’ file is found in one of these locations, load the environment variables using load_dotenv(). Proceed to step 3.

The following is run after the above step(s):

  1. Get the environment variables NLR_API_KEY and NLR_API_EMAIL (falling back to the

    deprecated NREL_API_KEY / NREL_API_EMAIL). If found, set them as global variables using set_developer_nlr_gov_key() / set_developer_nlr_gov_email().

Parameters:

path (Path | str, optional) – Path to environment file. Defaults to None.

h2integrate.resource.utilities.nlr_developer_api_keys.get_nlr_developer_api_key(env_path=None)#

Load the API key (NLR_API_KEY). This method does the following:

  1. check for NLR_API_KEY (or deprecated NREL_API_KEY) environment variable,

    return if found. Otherwise, proceed to Step 2.

  2. check if the key has already been set as a global variable from

    running set_nlr_key_dot_env(). If not set, proceed to Step 3.

  3. Attempt to set the key by calling set_nlr_key_dot_env().

  4. Check if the key has been set as a global variable. If found, return.

    Otherwise, raises a ValueError.

Parameters:

env_path (Path | str, optional) – Filepath to .env file. Defaults to None.

Raises:
  • ValueError – If NLR_API_KEY was not found as an environment variable and the path to the environment file was not input.

  • ValueError – If NLR_API_KEY was not found as an environment variable and not set properly using the environment path.

Returns:

str – API key for NLR Developer Network.

h2integrate.resource.utilities.nlr_developer_api_keys.get_nlr_developer_api_email(env_path=None)#

Load the API email (NLR_API_EMAIL). This method does the following:

  1. check for NLR_API_EMAIL (or deprecated NREL_API_EMAIL) environment variable,

    return if found. Otherwise, proceed to Step 2.

  2. check if the email has already been set as a global variable from running

    set_nlr_key_dot_env(). If not set, proceed to Step 3.

  3. Attempt to set the email by calling set_nlr_key_dot_env().

  4. Check if the email has been set as a global variable. If found, return.

    Otherwise, raises a ValueError.

Parameters:

env_path (Path | str, optional) – Filepath to .env file. Defaults to None.

Raises:
  • ValueError – If NLR_API_EMAIL was not found as an environment variable and the path to the environment file was not input.

  • ValueError – If NLR_API_EMAIL was not found as an environment variable and not set properly using the environment path.

Returns:

str – email for NLR Developer Network API.