"Avoid THIS Bad Practise In Python": An Introduction to .env Files

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ก.ย. 2024
  • Hardcoding your keys / sensitive information in your scripts is a strong red flag when it comes to coding. Let me show you a better alternative by using .env files to store your sensitive information!
    ▶ Become job-ready with Python:
    www.indently.io
    ▶ Follow me on Instagram:
    / indentlyreels

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

  • @pietraderdetective8953
    @pietraderdetective8953 8 หลายเดือนก่อน +3

    i really love your Python syntax which includes types both for the variables and the function return.
    not a lot of python youtube channels properly uses types like that.
    I'm currently learning C and Rust, and I have learned Cython before so these static typing are very important.

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

      Always happy to see an appreciator of type annotations in Python :) I programmed in Python without them for a while, and that freedom showed me why they were so important in the end. So my older tutorials might not have them always, but all my future tutorials will definitely always have them!

  • @fasanojp
    @fasanojp 6 หลายเดือนก่อน +2

    An alternative is to use the Python keyring package. An advantage is that the sensitive information is not stored in plain text on the local machine.

  • @alexjando4880
    @alexjando4880 ปีที่แล้ว +7

    Great video, but if you want to do something native to python, you could do it by using either simple json file, or by just iterating each line of the .env file and adding the environment variables yourself.

  • @SonuSingh-sn8qg
    @SonuSingh-sn8qg ปีที่แล้ว +1

    Awesome! Going to implement this tomorrow

  • @dk-ww3kp
    @dk-ww3kp ปีที่แล้ว +1

    You helped me so much with this video thank you keep up the awesome content👏🔥

  • @ali-g
    @ali-g ปีที่แล้ว +6

    Awesome video! What is the difference between a config file and a .env file?

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

      You can actually do the same job with a config file. However, generally in a config file you save non-sensitive information.

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

    I think this is doing the same thing when I store variables in my Linux environment. per the .profile, or .bashrc. Is that accurate? I use this method to store detail but you have to keep an eye on file permissions. On top of that I have went so far and finding ways to encrypt the info using a seed file, but again finding suitable file permissions and places to store the seed should be concerns.

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

    Awesome! Now I finally understand what .env files are for :D

  • @MyManJohnny
    @MyManJohnny ปีที่แล้ว +4

    Another option would be to create a json file, and then write a simple wrapper class that you can use to load and access the data.

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

    Providing types for every variable is maybe more professional aproach, but it's so iritating, I never do it

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

    I keep a .env.example file in my repos whenever I need to communicate to users and other devs which environment keys need to be set up.

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

    Great video🎉, compare to normal json file or txt file, is there any advantage using .env file?

  • @AliHamza-en8cn
    @AliHamza-en8cn ปีที่แล้ว +2

    Great video. But anybody can have access env in local. Any alternative to be more secure and how the use in production.

    • @Indently
      @Indently  ปีที่แล้ว +5

      I don't understand what what you mean. The only person who has access to your env on local is you and whoever else uses your computer.

    • @AliHamza-en8cn
      @AliHamza-en8cn ปีที่แล้ว +1

      @@Indently I mean, for example, you have a project already in an exe that is passed to the end user and the script has to connect to the database if we save it in env, the people who access that computer will be able to see it and that env is not encrypted, right?

    • @Moonz97
      @Moonz97 ปีที่แล้ว +4

      ​@@AliHamza-en8cn build a server in between those layers as a relay. So your end user connects to your server, and your server connects to the DB. More secure that way since you can control what goes in your DB and users cant access the DB directly.

    • @AliHamza-en8cn
      @AliHamza-en8cn ปีที่แล้ว +1

      @@Moonz97 Thanks bro for information. Any suggestions of server?

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

    Make a a video how to atore environment variables/secret variables in github and retrieve in it the code , because if i hist the github repo on a platform like c panel , i want make sure api keys correctly retrieved

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

    Good video, but in my case very strange. I took over the source code from you and also .env. But if I execute print('USERNAME...) I see my original USERNAME and not the USERNAME written in .env. Do you know why?

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

      In this instance, if you wish to print to console, you need a formatted string, as you are treating the print statement as plain text.
      print(f"My username is {USERNAME}!")
      This assumes you have imported USERNAME from the .env and already instanced and defined it in the script you are currently working in.

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

      @@TheRealLAC under Ubuntu the variable USERNAME is reserved. If I take username it works.

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

    helpful. thank you.

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

    Which IDE or text editor you are using? Please reply

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

    Whats your code editor you use

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

    Which Is your theme?

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

    Thanx!

  • @MatthewPerez-x6y
    @MatthewPerez-x6y 17 วันที่ผ่านมา

    Greyson Throughway

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

    Which IDE is this?

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

      pycharm's new theme

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

      ​@@yurix650is there a name for the new theme i can't find it

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

    Great video.

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

    tysm!!

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

    Thanks!

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

      Thank you for your genorosity! :)

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

      No no sir!!! This was cool!!!

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

    Excellent❤

  • @aafan.kuware
    @aafan.kuware ปีที่แล้ว

    I use python-decouple.

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

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

    in@it host-ip

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

    What about bad english ?

  • @Oler-yx7xj
    @Oler-yx7xj ปีที่แล้ว +2

    I thought, your channel was called Identity...

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

    sei italiano?

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

    Just like Env reader in dart