Home > other >  Storing API_KEY in Heroku
Storing API_KEY in Heroku

Time:03-26

I have a Python code that I want to run 24/7. After doing a bit research, I decided to deploy my code on Heroku. In order for my code to run, it needs to get an API key; however, I want to store the API key in a secure place.

So I stored the key in Heroku's config vars using the CLI's command config:set. However, I am not sure how to pull the key from config vars in order to store it in a variable in my code.

I am very new to all of this so I would really appreciate your help. I am open to storing my API key as well using different methods, whatever gets the job done in a beginner-friendly manner (git-crypt? etc.)

Thanks!

CodePudding user response:

The configvar is an environment variable available to the application at runtime:

api_key = os.environ.get("API_KEY", "default_val")

You could have a default value on local dev (if needed)

  • Related