Reputation: 52665
I need to push Python
script to Git
repo. Script contains variables with personal data like USER_NAME = "some_name"
and USER_PASS = "some_password"
. This data could be accessible for other users. I want to hide this data.
I found following approach:
data.py
module with USER_NAME = "some_name"
and USER_PASS = "some_password"
data.pyc
change main script source: variables should be accessible like
import data
username = data.USER_NAME
password = data.USER_PASS
data.py
and push data.pyc
to repoThis was promising, but actually data in data.pyc
appears like ???some_namet???some_passwords???
and still could be recognized as username and password.
So what is the best practices to hide data in Python
script?
Upvotes: 4
Views: 1702
Reputation: 876
You should never put sensitive pieces of information inside your code neither store them into a public repository.
It's better to follow Joel Goldstick's suggestion and modify your code to get passwords from private sources, e.g. local environment variables or local modules.
Try googling for "python store sensitive information" to look at some ideas (and involved issues).
Upvotes: 1
Reputation: 4493
Include in git repo code to read those things from environment variables. On the target machine, set those environment variables. This could be done by hand, or with a script that you don't include in your repo. Include instructions in your readme file
Upvotes: 2
Reputation: 7308
Try using an YAML file and not pushing it to your repo, like from here. You can use the python module yaml
to read the data.
Upvotes: 1