Load Environment Variables From .env Files in Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 พ.ค. 2023
  • Today we go a little bit deeper into the Python dotenv module, which allows us to load environment variables from .env files.
    ◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
    📚 Programming Books & Merch 📚
    🐍 The Python Bible Book: www.neuralnine.com/books/
    💻 The Algorithm Bible Book: www.neuralnine.com/books/
    👕 Programming Merch: www.neuralnine.com/shop
    🌐 Social Media & Contact 🌐
    📱 Website: www.neuralnine.com/
    📷 Instagram: / neuralnine
    🐦 Twitter: / neuralnine
    🤵 LinkedIn: / neuralnine
    📁 GitHub: github.com/NeuralNine
    🎙 Discord: / discord
    🎵 Outro Music From: www.bensound.com/
  • วิทยาศาสตร์และเทคโนโลยี

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

  • @kenkioqqo
    @kenkioqqo 11 หลายเดือนก่อน +8

    I'm on your third video, and it's absolutely mind-boggling how you happen to be teaching the exact Python concepts I want to learn quickly for my current project. You're just the helper I was looking for.

  • @beastlorion5245
    @beastlorion5245 5 หลายเดือนก่อน +1

    Awesome tutorial. Thanks for making this quick and painless

  • @Dev_Gisoun
    @Dev_Gisoun 12 วันที่ผ่านมา

    Your lecture was very easy to follow and effective! It was really helpful for me.

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

    Ironically, I just began using python-decouple for .env files which happens to be one of a few late improvements in my scripting. Love this channel, definitely a gold mine of dev related knowledge.

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

    Hey, thanks a bunch! So, the other day I accidentally made my OpenAI API key public for a short while, and had to delete the whole repository. But thanks to your help, I'm following best practices now. By the way, I can't help but notice your white board - looks like there are some differential equations and a neural network model, maybe some content related to gradient descent too? It's really intriguing!

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

    Learn't so much from this channel ❤

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

    Thank you soo much, it saved me hours of debugging!!! 💟

  • @tanuj05
    @tanuj05 3 หลายเดือนก่อน +1

    Nice and informative video

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

    Best channel ever for python ❤❤🎉🎉🎉

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

    Awesome tutorial 👍Need more Flask and Django.

  • @Roman-kn7kt
    @Roman-kn7kt หลายเดือนก่อน

    Oh, that look “If you don’t understand through my video what I explained to you, I’ll punch you”😅😅😅
    Thank you so much for your content, sir, you are the best!

  • @appaloosa_
    @appaloosa_ 11 หลายเดือนก่อน +3

    Hello, I am confused by your use of $ and non-string values within your dotenv file. What is the purpose of this? Sorry if this is a dumb question & thanks for your video

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

    Thanks for sharing 👍

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

    Thanks for this tutorials, actually have been struggling to get a way around this .env thing for a while with a kivy app.
    Please I mean to ask, is this a very secure way to do it or there are other ways plus when I try to use it with my kivy app, bulldozer keeps giving me errors whenever it tries to download the dotenv module. Thanks in anticipation boss

  • @birdie123
    @birdie123 ปีที่แล้ว +8

    What are the pros and cons of using .ini, .env, .toml and .yaml for storing environment variables?

    • @moviesnight248
      @moviesnight248 7 หลายเดือนก่อน +5

      The choice of a configuration format for storing environment variables (or other configuration settings) depends on various factors, including ease of use, readability, and the specific needs of your application.
      .ini:
      Pros:
      Simple and Human-Readable: .ini files are straightforward to read and write. They use a plain text format with a simple key-value structure.
      Widely Supported: .ini files are supported by a wide range of programming languages and libraries, making them versatile for configuration.
      Cons:
      Limited Structure: .ini files lack complex data types, which can be a limitation for more advanced configuration needs.
      No Nested Structures: .ini files do not support nested structures, making it harder to organize complex configurations.
      .env (Environment Variables):
      Pros:
      Security: .env files are a secure way to store sensitive environment variables since they are typically not committed to version control.
      Platform-Agnostic: .env files are compatible with most platforms and languages, and they can be used in different development and deployment environments.
      Cons:
      Limited to Key-Value Pairs: .env files are limited to key-value pairs and don't support complex data structures.
      No Comments or Metadata: .env files lack the ability to add comments or metadata, making it harder to provide context for each variable.
      .toml:
      Pros:
      Rich Data Types: TOML supports a wide range of data types, including arrays, tables, and nested structures.
      Human-Readable: TOML is designed to be easy to read and write for humans.
      Comments: TOML allows comments, which can provide valuable context for each variable.
      Cons:
      Complexity: The richer data types in TOML can add complexity to the configuration, which may not be necessary for simple settings.
      .yaml (YAML):
      Pros:
      Highly Readable: YAML is known for its high readability and is often used for configuration files.
      Rich Data Types: YAML supports complex data structures, including lists and dictionaries, making it suitable for more complex configurations.
      Comments: Some YAML implementations support comments, providing context for variables.
      Cons:
      Indentation Sensitive: YAML relies on indentation for structure, which can be a source of issues when formatting is inconsistent.
      Potential Security Risks: Be cautious when using YAML for sensitive data, as it's not designed for security like .env files.
      In summary, the choice of format depends on your specific requirements. If you need a simple, human-readable format, .ini or .env might be suitable. If you need richer data types and nesting, TOML and YAML are better choices. Additionally, consider security, compatibility with your development stack, and whether comments and metadata are important for providing context in your configuration files.

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

    Thanks for this tutorial
    Which plugin do you use in Pycharm to detect .env and .secret files

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

      I also did the same as in video but getting error like " Unresolved reference 'dotenv' "

  • @manifestasisanubari
    @manifestasisanubari 3 หลายเดือนก่อน

    Is it recommended to store list and integer in .env? Because I need to convert `os.getenv()` with `ast.literal_eval` before passing as a variable. I store related RSS URL as a list in my script.

  • @hamzazahidulislam3490
    @hamzazahidulislam3490 2 หลายเดือนก่อน

    Thanks

  • @user-lo3xm2ff9w
    @user-lo3xm2ff9w 4 หลายเดือนก่อน

    cool man
    thanks

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

    maybe can add to your python tip&tricks playlist or add a series of python 3rd party useful toolkits list XD

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

    what happens when you have more than one .env file ?

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

    I did the same as like in video but getting this erro "Unresolved reference 'dotenv'". Could someone help me

  • @The-Martian73
    @The-Martian73 ปีที่แล้ว

    What is going on guys welcome back to ... we are going to develop brains !!❤

  • @michaeljosiah536
    @michaeljosiah536 6 หลายเดือนก่อน +1

    Does anybody know how to make this work when you make your Python file into a .exe Python file?

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

    What is this black colour tool
    Python which version?

  • @sayalikhairnar3166
    @sayalikhairnar3166 4 หลายเดือนก่อน

    I am not able to install dotenv. It is showing - could not be able to find the right version. Anybody know it's solution??

    • @mbegaliful
      @mbegaliful 4 หลายเดือนก่อน

      I had a similar issue because I was trying to install: dotenv instead of python-dotenv

  • @daviesemmanuel8047
    @daviesemmanuel8047 6 หลายเดือนก่อน

    I did the exact same thing but I keep getting (None)

    • @daviesemmanuel8047
      @daviesemmanuel8047 6 หลายเดือนก่อน

      Nevermind I forgot to save the .env file

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

    "Let us get right into it," you say. I think you already did.
    This "so let's get started" thingie is all over TH-cam -- always spoken by people who have already started.
    One thank-you, though: thank you for skipping the "without further ado."

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

      Yes, just like hello, hi, etc. are used by a lot of people. Does that mean that we should stop using those?

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

    I struggle to see the benefit of using environment variables loaded from a file compared to loading setting directly from a file (json, ini) into program variables. It seems unnecessary and inefficient to have to bother the operating system every time you need a value.

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

      So do I, but I have to say that they are incredibly useful if your application can be run in a docker container because it's the easiest way to provide configuration in that situation

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

      It's industry standard, especially when deploying workloads in containers/serverless

  • @maliquewilliams983
    @maliquewilliams983 19 วันที่ผ่านมา

    Subscribe. I feel like this is illegal to learn for free.