Advertisement
pawptart

Untitled

Apr 8th, 2020
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. # Environment variables are best practice for securing credentials in Python,
  2. # you can use them either with builtin os library (enough for small number of
  3. # credentials) or the dotenv library which would be good for handling a larger
  4. # number of credentials.
  5.  
  6. ####################
  7. ## credentials.py ##
  8. ####################
  9. import os
  10.  
  11. def export_credentials():
  12.     os.environ['username'] = 'client_username'
  13.     os.environ['password'] = 'secret_password'
  14.  
  15. ###############
  16. ## script.py ##
  17. ###############
  18. from credentials import export_credentials
  19. import os
  20.  
  21. export_credentials()
  22.  
  23. # The following code retrieves your credentials and has an added bonus of
  24. # throwing an error if either is not set
  25. username = os.environ.get('username')
  26. password = os.environ.get('password')
  27.  
  28. ##########################################
  29. ## .gitignore (if you are using Github) ##
  30. ##########################################
  31. credentials.py # This line keeps the credentials file from being committed to source control
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement