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?
Asked
Active
Viewed 1,709 times
0
-
2Neither. Store it outside the script and have the script read from the file(which isn't stored in any repository). – ewokx Nov 23 '20 at 09: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 Nov 23 '20 at 09:16
2 Answers
3
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

Serial Lazer
- 1,667
- 1
- 7
- 15
-
-
2Of course you shouldnt be uploading the `example.cfg`! Thats only for your instance – Serial Lazer Nov 23 '20 at 09:36
1
You 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

MajaOlsz
- 11
- 3