Ask coding questions

← Back to all posts
Hiding Passwords and Secret Keys on Python's code using
LeonGrin (40)

What is the best way to hide Passwords and Secret Keys in a Python's code using

Answered by kaldisberzins (346) [earned 5 cycles]
View Answer
kaldisberzins (346)

There is this special file that you can use called .env (don't put anything before the dot). Nobody else who views your code will be able to see it. You can store passwords and other stuff in it and then reference to it in your code. Here is a comprehensive guide to using this type of file: (scroll down further).

LeonGrin (40)

@kaldisberzins Thank you for your reply. Could you please take a look at the image that I am attaching and see if I did it the right way?

ash15khng (721)

@LeonGrin Your file name is correct, but you can't put the export in front of the var name, or I think it will be considered part of the var name.