So I'm working on with an api from IsThereAnyDeals and I'm wondering where I should store my API key? Is it possible to store it remotely or is it fine to just store it inside the script?
- 2Neither. Store it outside the script and have the script read from the file(which isn't stored in any repository).ewokx– ewokx2020-11-23 09:08:48 +00:00Commented Nov 23, 2020 at 9:08
- You only need to store it remotely (securely on the host server) if you’re going to deploy it somewhere. Otherwise keep it a “secret” (local file).JBallin– JBallin2020-11-23 09:16:06 +00:00Commented Nov 23, 2020 at 9:16
Add a comment |
2 Answers
ConfigParser is a good choice to setup your configuration-files in Python.
Something like this:
import configparser cfg = configparser.ConfigParser() cfg.read('example.cfg') print(cfg.get('KEYS', 'api_key', raw='')) example.cfg:
[KEYS] api_key: @#$@GSSAS 2 Comments
Dave Cordero
My API key will still be exposed. It that okay?
Serial Lazer
Of course you shouldnt be uploading the
example.cfg! Thats only for your instanceYou can add your cfg file to .gitignore, so that this file doesn't get uploaded, when you do a git commit.
You can read more about that topic here: How to ignore certain files in Git