Setting up automated testing means I have to be able to pull in API keys where needed without storing in the notebook. This is easy to do with python-dotenv.
Include this cell to load variables from env:
%%capture
# Load variables from the .env file if it exists
# Use %%capture to suppress messages
%load_ext dotenv
%dotenv
The %%capture will suppress warnings if no .env file can be found (such as on Binder etc).
The include something like:
# Insert your Trove API key
API_KEY = "YOUR API KEY"
# Use api key value from environment variables if it is available
if os.getenv("TROVE_API_KEY"):
API_KEY = os.getenv("TROVE_API_KEY")
To give users the opportunity to insert their own key.
Setting up automated testing means I have to be able to pull in API keys where needed without storing in the notebook. This is easy to do with python-dotenv.
Include this cell to load variables from env:
The
%%capture
will suppress warnings if no.env
file can be found (such as on Binder etc).The include something like:
To give users the opportunity to insert their own key.