Python/netrc
From mn/geo/geoit
The netrc module can be a nice way to store credentials securely:
import netrc
HOST = 'smtp.gmail.com'
secrets = netrc.netrc()
username, account, password = secrets.authenticators( HOST )
Then in your ~/.netrc file include the following:
machine smtp.gmail.com
username your_username
password your_password
Make sure the mode is safe on the .netrc file, and you're set! You can easily call the netrc settings from any python script.