Andersson
Andersson

Reputation: 52665

How to hide personal data in Python script

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:

This 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

Answers (3)

davidedb
davidedb

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

joel goldstick
joel goldstick

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

Eli Sadoff
Eli Sadoff

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

Related Questions