GLAM-Workbench / glam-workbench.github.io

https://glam-workbench.github.io/
25 stars 6 forks source link

Use python-dotenv to store keys and define dev environment #54

Closed wragge closed 10 months ago

wragge commented 2 years ago

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.

wragge commented 2 years ago

I've also started using .env to set GW_STATUS=dev. Again this can be used to prepare tests in the dev environment (such as feeding in parameters).