Storing the secrets (passwords) in a separate file

アレックス picture アレックス · Aug 26, 2014 · Viewed 38.2k times · Source

What's the simplest way to store the application secrets (passwords, access tokens) for a Python script? I thought it'd be a *.yml file like in Ruby but surprisingly I found that it wasn't the case. So what is it then? What are the most simplest solutions?

I want to put them in a separate file because that way I'll be able not to push that file to a github repository.

Answer

kecer picture kecer · Aug 26, 2014

I think storing credentials inside another *py file is your safest bet. Then just import it. Example would look like this

config.py

username = "xy"
password = "abcd"

main.py

import config
login(config.username, config.password)