Correct way to protect a private API key when versioning a python application on a public git repo
- by systempuntoout
I would like to open-source a python project on Github but it contains an API key that should not be distributed.
I guess there's something better than removing the key each time a "push" is committed to the repo.
Imagine a simplified foomodule.py :
import urllib2
API_KEY = 'XXXXXXXXX'
urllib2.urlopen("http://example.com/foo?id=123%s" % API_KEY ).read()
What i'm thinking is:
Move the API_KEY in a second key.py module importing it on foomodule.py; i would then add key.py on .gitignore file.
Same as 1 but using ConfigParser
Do you know a good programmatic way to handle this scenario?