h2integrate.resource.utilities.nrel_developer_api_keys#
Functions
|
Load the NREL_API_EMAIL. |
|
Load the NREL_API_KEY. |
|
Load environment variables from a text file. |
|
Set email as the global variable developer_nrel_gov_email. |
Set key as the global variable developer_nrel_gov_key. |
|
|
Sets the environment variables NREL_API_EMAIL and NREL_API_KEY from a .env file. |
- h2integrate.resource.utilities.nrel_developer_api_keys.set_developer_nrel_gov_key(key)#
Set key as the global variable developer_nrel_gov_key.
- Parameters:
key (str) -- API key for NREL Developer Network. Should be length 40.
- h2integrate.resource.utilities.nrel_developer_api_keys.set_developer_nrel_gov_email(email)#
Set email as the global variable developer_nrel_gov_email.
- Parameters:
email (str) -- email corresponding to the API key for NREL Developer Network.
- h2integrate.resource.utilities.nrel_developer_api_keys.load_file_with_variables(fpath, variables=['NREL_API_KEY', 'NREL_API_EMAIL'])#
Load environment variables from a text file.
- 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 ["NREL_API_KEY", "NREL_API_EMAIL"].
- Raises:
ValueError -- If an environment variable is not found or found multiple times in the file.
- h2integrate.resource.utilities.nrel_developer_api_keys.set_nrel_key_dot_env(path=None)#
Sets the environment variables NREL_API_EMAIL and NREL_API_KEY from a .env file. The following logic is used if path is input and exists:
- If the filename of the path is '.env', load the environment variables using load_dotenv().
Proceed to Step 3.
- 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:
- check for possible locations of the '.env' file. Searches the current working directory,
the ROOT_DIR, and the paret 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):
- Get the environment variables NREL_API_KEY and NREL_API_EMAIL. If the NREL_API_KEY
variable exists, then set it as a global variable using set_developer_nrel_gov_key(). If the NREL_API_EMAiL variable exists, then set it as a global variable using set_developer_nrel_gov_email().
- Parameters:
path (Path | str, optional) -- Path to environment file. Defaults to None.
- h2integrate.resource.utilities.nrel_developer_api_keys.get_nrel_developer_api_key(env_path=None)#
Load the NREL_API_KEY. This method does the following:
check for NREL_API_KEY environment variable, return if found. Otherwise, proceed to Step 2.
- check if NREL_API_KEY has already been set as a global variable from
running set_nrel_key_dot_env(). If NREL_API_KEY has not been set, proceed to Step 3.
Attempt to set the NREL_API_KEY by calling set_nrel_key_dot_env().
- Check if NREL_API_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 NREL_API_KEY was not found as an environment variable and the path to the environment file was not input.
ValueError -- If NREL_API_KEY was not found as an environment variable and not set properly using the environment path.
- Returns:
str -- API key for NREL Developer Network.
- h2integrate.resource.utilities.nrel_developer_api_keys.get_nrel_developer_api_email(env_path=None)#
Load the NREL_API_EMAIL. This method does the following:
check for NREL_API_EMAIL environment variable, return if found. Otherwise, proceed to Step 2.
- check if NREL_API_EMAIL has already been set as a global variable from running
set_nrel_key_dot_env(). If NREL_API_EMAIL has not been set, proceed to Step 3.
Attempt to set the NREL_API_EMAIL by calling set_nrel_key_dot_env().
- Check if NREL_API_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 NREL_API_EMAIL was not found as an environment variable and the path to the environment file was not input.
ValueError -- If NREL_API_EMAIL was not found as an environment variable and not set properly using the environment path.
- Returns:
str -- API key for NREL Developer Network.