Python has a module to ask for passwords called getpass. Its functionality is very similar to the standard input() function but this module hides the user input from the terminal.

Calmcode

How to Handle Secrets in Python

Put secrets in file secrets.json

Make sure to add this file to .gitigore file!

{
    "confluence": {
        "username": "my_name",
        "password": "password"
    }
 }
def get_value_from_json(json_file, key, sub_key):
   try:
       with open(json_file) as f:
           data = json.load(f)
           return data[key][sub_key]
   except Exception as e:
       print("Error: ", e)

username = get_value_from_json("secrets.json", "confluence", "username")
password = get_value_from_json("secrets.json", "confluence", "password")