Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Environment variables are best practice for securing credentials in Python,
- # you can use them either with builtin os library (enough for small number of
- # credentials) or the dotenv library which would be good for handling a larger
- # number of credentials.
- ####################
- ## credentials.py ##
- ####################
- import os
- def export_credentials():
- os.environ['username'] = 'client_username'
- os.environ['password'] = 'secret_password'
- ###############
- ## script.py ##
- ###############
- from credentials import export_credentials
- import os
- export_credentials()
- # The following code retrieves your credentials and has an added bonus of
- # throwing an error if either is not set
- username = os.environ.get('username')
- password = os.environ.get('password')
- ##########################################
- ## .gitignore (if you are using Github) ##
- ##########################################
- credentials.py # This line keeps the credentials file from being committed to source control
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement