14

Even though secrets are for masking confidential information, I need to see the value of the secret for using it outside Databricks. When I simply print the secret it shows [REDACTED].

print(dbutils.secrets.get(scope="myScope", key="myKey"))

Out:
[REDACTED]

How can I print the secret value?

aykcandem
  • 806
  • 1
  • 6
  • 18

1 Answers1

35

Databricks redacts secret values that are read using dbutils.secrets.get(). When displayed in notebook cell output, the secret values are replaced with [REDACTED].

Although it is not recommended, there is a workaround to see actual value with a simple for loop trick. So, you will get the value separated by spaces.

value = dbutils.secrets.get(scope="myScope", key="myKey")

for char in value:
    print(char, end=" ")

Out:
y o u r _ v a l u e
aykcandem
  • 806
  • 1
  • 6
  • 18
  • This will print out [REDACTED] instead of the value, no? This should print the value of the secret, with spaces: `' '.join([x for x in dbutils.secrets.get(scope="myScope", key="myKey")])` – svacx Nov 11 '21 at 10:14
  • 1
    I forgot to add space to the end argument. (end=" "). It should work fine. – aykcandem Nov 11 '21 at 10:41
  • this is a useful hack especially if you're debugging and maybe want to make sure databricks is using the correct keys – Derek O Sep 09 '22 at 21:20