Hide API keys in Python scripts using python-dotenv, .env, and .gitignore

แชร์
ฝัง
  • เผยแพร่เมื่อ 6 ก.ย. 2024
  • Sometimes you want to make your code public, but don't want to share an API key, email address, or password with the world. Using a combination of python-dotenv and a .gitignore file, you'll be good to go!
    Note: If you're using Jupyter Notebooks, make sure you're not printing your API keys all over the place!! (and also: your .env file will need to be in the same directory as your .ipynb)
    repo: github.com/jso...
    python-dotenv: github.com/the...
    gitignore: gitignore.io/

ความคิดเห็น • 83

  • @janvichitroda4689
    @janvichitroda4689 2 ปีที่แล้ว +16

    Wow, this is one of the best tutorials I have seen. Explained everything so well, now there is no need to search for any other tutorial on this topic. Thank you.

    • @-Anubhab
      @-Anubhab 5 หลายเดือนก่อน

      totally agreed

  • @mblackonline1059
    @mblackonline1059 ปีที่แล้ว +1

    Thank you for posting this. It really helped with understanding how to use the dotenv module to hide my API keys. I especially liked the tip on creating the content for gitignore file.

  • @brandonconner7319
    @brandonconner7319 2 ปีที่แล้ว +2

    I was having issues with conflicting instructions until I found your video. Thank you! Great content, great presentation

    • @jsoma
      @jsoma  2 ปีที่แล้ว +2

      You're welcome!

  • @retroblackztar
    @retroblackztar ปีที่แล้ว +1

    Thanks a lot for your explanation, I used this video to configure .env with java

  • @devstuff92
    @devstuff92 2 ปีที่แล้ว +2

    Most simple explanation ever, I've struggled with this lol thank you

  • @ldELuxEl
    @ldELuxEl 2 ปีที่แล้ว +1

    When I deploy my app to a server(heroku for example) from GitHub - it does not have env file(obviously). But how do I set it up so that my app works?

  • @_Gintoki
    @_Gintoki 2 ปีที่แล้ว +1

    Always found the config files and .env file scary, but after seeing your video it seems so easy to work with and super logical too!

  • @alisherpulatov3587
    @alisherpulatov3587 ปีที่แล้ว

    Finally, best ever explanation about how to use python-dotenv. You made my life easier, Bro! Thank You so much for this video.

  • @Reeg3x
    @Reeg3x 2 ปีที่แล้ว +1

    When you have liked this video and still revisit a year later.

  • @xiaolinghe4314
    @xiaolinghe4314 2 ปีที่แล้ว

    very clear and intuitive instead of just throwing jargons!

  • @arnavraina2615
    @arnavraina2615 2 ปีที่แล้ว

    One of the.... no No only one clearest explanation!! Thank you very much!

  • @Moist_yet_Crispy
    @Moist_yet_Crispy 2 ปีที่แล้ว

    Great video Jonathan, this helped alot. I was stuck in the weeds for a bit.

  • @edsonsabino
    @edsonsabino 2 ปีที่แล้ว

    Great! I was struggling to hide credentials of a SQL database and your video helped me get it done.
    Thankyou!!

  • @anton9410
    @anton9410 2 ปีที่แล้ว

    Perfect explanation, with a pinch of satire!

  • @joydeepsarkar3092
    @joydeepsarkar3092 7 หลายเดือนก่อน

    Glad I came across this tutorial of yours! Very helpful!

  • @milkmangames100
    @milkmangames100 2 ปีที่แล้ว

    Best tutorial I have seen on this topic. Good job brother.

  • @gold4963
    @gold4963 3 ปีที่แล้ว +1

    This was an awesome, clear tutorial and exactly what I needed! Thanks so much!

  • @maurillekobri9484
    @maurillekobri9484 2 ปีที่แล้ว

    Clean and excellent explanation. Thanks a million, Jonathan Soma!

  • @misosoup7531
    @misosoup7531 2 ปีที่แล้ว

    This was the best tutorial for me to understand how to use dotenv in python!! tysm

  • @dallaspalumbo9889
    @dallaspalumbo9889 ปีที่แล้ว

    thank you for making this was the key to success

  • @asoniox
    @asoniox 2 ปีที่แล้ว

    Clear and straight to the point! Thank you!

  • @sinothi
    @sinothi ปีที่แล้ว

    Amazing tutorial. Cannot wait to learn more stuff from you!!!

  • @eziola
    @eziola ปีที่แล้ว

    Great video! You showed us how to read a .env variable into a python module. Next would be how do I set or write to or update a .env variable from my python module? This is something I have to do with refresh tokens. I have to read the last refresh token from the .env file, get a new refresh token back, and save the new refresh token back into the .env variable. Hopefully that make sense! It would be amazing to know how to do that!

  • @yuliyasheichenka1175
    @yuliyasheichenka1175 ปีที่แล้ว

    Wonderful tutorial, very clear and precise! Thank you a lot!

  • @jtl_1
    @jtl_1 2 ปีที่แล้ว

    Indeed, what a great tutorial. Covers all my questions.

  • @aishwaryamurugappan5138
    @aishwaryamurugappan5138 2 ปีที่แล้ว

    Loved it, Clear and just to the point, very well explained! Keep up the good work :)

  • @SAURABHSINGH-fl2ep
    @SAURABHSINGH-fl2ep 9 หลายเดือนก่อน

    Exactly what i needed, thanks

  • @jayatidixit5260
    @jayatidixit5260 2 ปีที่แล้ว

    if I am deploying a django project and in the settings.py file I added dotenv but when I deploy it on pythonanywhere it shows error while running wsgi application dotenv module not found

  • @kevon217
    @kevon217 ปีที่แล้ว

    Helpful and thorough. Thanks!

  • @stevefox7469
    @stevefox7469 2 ปีที่แล้ว

    Thanks - really well explained. Super simple when it is explained as well you did!

  • @adityavaste3732
    @adityavaste3732 2 ปีที่แล้ว

    That was the complete tutorial, thanks for it.

  • @ake_bangkok9312
    @ake_bangkok9312 ปีที่แล้ว

    many thanks, it is what I'm looking for

  • @ignasskarzinskas7126
    @ignasskarzinskas7126 2 ปีที่แล้ว

    when i try to print the variable it prints me none. Im using a virtual env if its somehow related

  • @alanalmeida7887
    @alanalmeida7887 3 ปีที่แล้ว

    Thanks, Well Explained! 15 minutes well spent, got to learn a lot:)

  • @gpc1290
    @gpc1290 ปีที่แล้ว

    Where do you save the .env file so that it can be found by the Python os.getenv() method?

  • @JoNNy8904
    @JoNNy8904 ปีที่แล้ว

    Phenomenal tutorial!

  • @amphetaminedaydream
    @amphetaminedaydream 2 ปีที่แล้ว

    Perfectly explained. Thanks.

  • @MohanRaj-fo6uk
    @MohanRaj-fo6uk 2 ปีที่แล้ว

    Awesome, You have clearly explained it.

  • @LennWeltmeister
    @LennWeltmeister 2 ปีที่แล้ว

    One thing that's still in my brain: if we don't actually send the file, how can the server recover it?

  • @LHM1226
    @LHM1226 10 หลายเดือนก่อน

    I love your way of storing data . But what will you do if you want to store a Python list as environment variable outside the code?

    • @anibaldk
      @anibaldk 8 หลายเดือนก่อน

      Bit old by now but you could store it as:
      1. JSON string
      2. Regular string which you parse
      In any case, you can always resort to base64 in case of strange annoying characters

  • @the_flash_light
    @the_flash_light 2 ปีที่แล้ว

    Thanks for your explanation, set me interested in and was like really useful to know!

  • @ssk-ct7cr
    @ssk-ct7cr ปีที่แล้ว

    Very complete! Thanks for sharing! :)

  • @mistiksanju500
    @mistiksanju500 2 ปีที่แล้ว

    Please help me with my problem
    When i used .env without .gitignore it worked and bot started running
    But when i posted .gitignore file it not displayed the .env in repo all fine,
    But when i deployed it in heroku
    The bot is not working

  • @fotromba
    @fotromba ปีที่แล้ว

    Hey, great video! I've always had the doubt, what if build a web app and deploy it using Heroku or something. If my app connects to a cloud server like Firebase with a password and I have that in my gitignore file, will people be able to use my web app? Or will my app not be able to find that password?

  • @GoodguyGastly
    @GoodguyGastly 2 ปีที่แล้ว

    Thank you for such an excellent tutorial!

  • @noco2605
    @noco2605 2 ปีที่แล้ว

    Thanks a lot, finally it becomes clear to me

  • @jknyt
    @jknyt 2 ปีที่แล้ว

    Thanks! relaxing tutorial

  • @nelsonjoseph3673
    @nelsonjoseph3673 11 หลายเดือนก่อน

    Best one so far. :)

  • @itaysagy3756
    @itaysagy3756 2 ปีที่แล้ว

    Very informative. Thank you!

  • @iheleanbeefpatty
    @iheleanbeefpatty 2 ปีที่แล้ว

    Thank you Sir! Subscribed!

  • @realserax
    @realserax 5 หลายเดือนก่อน

    Hey great Video but I got a question,
    I am currently using a .env to hide my mySQL connection data inside of my python script, and when using nuitka this .env is not hidden and instead its shown in the path of the exe. Is there a way to fix it, or do you maybe know a alternative I can do to hide my mySQL connection data like the password? Or is nuitka so safe that people cant get my sourcecode at all?

  • @louisdonofrio7376
    @louisdonofrio7376 ปีที่แล้ว

    is it possible to make a .env file that requires a password to open? I have a python script I need to share with my team but I am not uploading it to git just sending them over the folder to run when they need.

  • @investandcyclecheap4890
    @investandcyclecheap4890 2 ปีที่แล้ว

    thank you this was very helpful. What about for virtual machines, would I just be able to create a .env file right on my VM and pull the secure info from there?

  • @assef444
    @assef444 2 ปีที่แล้ว

    great explanation !

  • @koushikromel
    @koushikromel ปีที่แล้ว

    Explained well man! 👏🏻

  • @aditya_01
    @aditya_01 2 ปีที่แล้ว

    Thanks great and really helpful video.

  • @basilihuoma5300
    @basilihuoma5300 2 ปีที่แล้ว

    Nice explanation, Appreciate it.

  • @newgenart482
    @newgenart482 ปีที่แล้ว

    Thank you bro was super useful

  • @user-dc3jp4ee8c
    @user-dc3jp4ee8c 2 ปีที่แล้ว

    Very helpful video - thanks

  • @vaha2833
    @vaha2833 2 ปีที่แล้ว

    Thanks for explanation. Now i know....

  • @stephenthumb2912
    @stephenthumb2912 2 ปีที่แล้ว

    Any chance you do blockchain programming :)? This was really a great tutorial on something simple but obscure but important haha.

  • @ictteacheraj
    @ictteacheraj 2 ปีที่แล้ว

    Is it safe when you use it in locally only right just running in your local system? Is it safe in Pycharm only?

  • @anubhavborkotoky391
    @anubhavborkotoky391 2 ปีที่แล้ว

    Hello Sir, could you help me? I'm getting an error saying that it's a syntax error
    I uninstalled and reinstalled python-dotenv

  • @JamesPrenticez
    @JamesPrenticez 2 ปีที่แล้ว

    LMFAO - "Sometimes when your programming you have code or little bits and pieces that you dont want to share with the entire world - and I'm not just talking about you being embarrassed about your programming"

  • @stephonhenry-rerrie3997
    @stephonhenry-rerrie3997 3 ปีที่แล้ว

    very thorough thanks!

  • @Rich-yj7gr
    @Rich-yj7gr 2 ปีที่แล้ว

    Sorry, could you please explain, what is the benefit of this comparing to just saving them in a separate .py file that I can then add to gitignore?

    • @jsoma
      @jsoma  2 ปีที่แล้ว

      That's perfectly fine, too! I think this is just one of the more common techniques, maybe because people are used to putting .env files into gitignore as opposed to other files? Either way is okay!

  • @karjon1122
    @karjon1122 3 ปีที่แล้ว +1

    Just create a json file with ur data then load it in the script, no need to install any python libs

    • @alanalmeida7887
      @alanalmeida7887 3 ปีที่แล้ว

      ah yes that can be done too. But I feel it boils down to personal preference.

  • @SubhamSatapathy
    @SubhamSatapathy 2 ปีที่แล้ว

    Wow! I used to commit my codes with my API keys without bothering as I developed stuff for my firm. Seems I would need to improve upon my practices and hold up some standards.

  • @joseluisgiraldomorales3975
    @joseluisgiraldomorales3975 2 ปีที่แล้ว

    y si hay una persona que sabe de este método y consulta .env no le aparecen las claves??

  • @rashin4157
    @rashin4157 3 ปีที่แล้ว

    very helpful tutorials

  • @19holegolf
    @19holegolf 11 หลายเดือนก่อน

    Thank you!!!

  • @khalidhassani6173
    @khalidhassani6173 2 ปีที่แล้ว

    But what about if i want to share my python desktop app with a friend, how to keep my credentials secret?

    • @jsoma
      @jsoma  2 ปีที่แล้ว +1

      Unfortunately I don't think there's a good method for that situation. You either need to trust your friend with your credentials or allow them to input their own keys!

    • @khalidhassani6173
      @khalidhassani6173 2 ปีที่แล้ว

      @@jsoma my app gives the user the possibility to store some data in a mysql db and he w'ill receive a confirmation by email. I struggle with the way i should hude the sensitive information related to connexion to the db and the SMTP ones

    • @jsoma
      @jsoma  2 ปีที่แล้ว +1

      ​@@khalidhassani6173 hmmm. I think you'd want to have your desktop app call to a web service you control, and then the web service you control talks to the smtp service. maybe they register so you can track them and allow them to send, etc. That will be a real pain since it's a whole separate service to run beyond just your app, but I really can't think of a better route.

    • @khalidhassani6173
      @khalidhassani6173 2 ปีที่แล้ว

      @@jsoma thanks for the help, i should put some effort in this subject, learning is a long path full of thorns

  • @shiblyaziz4528
    @shiblyaziz4528 2 ปีที่แล้ว

    Thank you

  • @PihFrags
    @PihFrags ปีที่แล้ว

    Lovely video
    Bless you bro