Created
January 21, 2015 00:10
-
-
Save radcliff/47af9f6238c95f6ae239 to your computer and use it in GitHub Desktop.
One way to work with secrets in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
credentials.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
database: | |
username: some-cool-person | |
password: yeah-right | |
hostname: obscure.domain.com |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import yaml | |
# load yml file to dictionary | |
credentials = yaml.load(open('./credentials.yml')) | |
# access values from dictionary | |
username = credentials['database']['username'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage
.yml
file containing credentials (yaml uses spaces for indentation, similar to python).gitignore
this fileyaml.load(open('path/to/file.yml'))