Skip to content

Instantly share code, notes, and snippets.

@radcliff
Created January 21, 2015 00:10
Show Gist options
  • Save radcliff/47af9f6238c95f6ae239 to your computer and use it in GitHub Desktop.
Save radcliff/47af9f6238c95f6ae239 to your computer and use it in GitHub Desktop.
One way to work with secrets in Python
credentials.yml
database:
username: some-cool-person
password: yeah-right
hostname: obscure.domain.com
import yaml
# load yml file to dictionary
credentials = yaml.load(open('./credentials.yml'))
# access values from dictionary
username = credentials['database']['username']
@radcliff
Copy link
Author

Usage

  • create .yml file containing credentials (yaml uses spaces for indentation, similar to python)
  • .gitignore this file
  • import the yaml into a python script with yaml.load(open('path/to/file.yml'))
  • 🆒

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment