---
title: "Discussion on \"How To Use a .env File With Python\" | Hashnode"
description: "Discussion on \"How To Use a .env File With Python\". We've all been there before, pushing login credentials or API tokens to GitHub. This can cause many issues, like getting your account that's linked to the API you're using suspended. All because of bots finding your API token on GitHub. Perhaps someo..."
url: "https://hashnode.com/posts/how-to-use-a-env-file-with-python/61b0fe8fccd13f578941ed74"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How To Use a .env File With Python](https://lovelacecoding.hashnode.dev/how-to-use-a-env-file-with-python?utm_source=hashnode&utm_medium=feed)

We've all been there before, pushing login credentials or API tokens to GitHub. This can cause many issues, like getting your account that's linked to the API you're using suspended. All because of bots finding your API token on GitHub. Perhaps someo...

Dec 8, 2021 · 8 min read · lovelacecoding.hashnode.dev  
Updated Dec 16, 2024  
Read the article

-   [#python](https://hashnode.com/tag/python)
-   [#python3](https://hashnode.com/tag/python3)
-   [#python-beginner](https://hashnode.com/tag/python-beginner)
-   [#software-engineering](https://hashnode.com/tag/software-engineering)
-   [#developer](https://hashnode.com/tag/developer)

## Written by

[Louëlla Creemers](https://hashnode.com/@lovelacecoding)

@lovelacecoding · Rotterdam, The Netherlands

  
[View profile](https://hashnode.com/@lovelacecoding)

Microsoft MVP | Developer | Speaker | Content Creator

Heya! I'm Lou. I love coding and trying out new technology. I've been interested in a lot of different tech fields for 5 years now. I like to blog about stuff I'm currently learning about or about topics I hear / speak about on other social media platforms. I'm also Microsoft MVP. Want to hear more from me? Follow me or check me out on Twitter.

## Responses 2

Markdown supported · ⌘↵ to post

[Sandeep](https://hashnode.com/@sandeepx21)

[Dec 9, 2021](https://hashnode.com/posts/how-to-use-a-env-file-with-python/61b0fe8fccd13f578941ed74/comment/61b192511907c16be2edf80b)

Why do we need to write the variable in uppercase in .env file? Is it required?

[Sandeep](https://hashnode.com/@sandeepx21)

[Dec 10, 2021](https://hashnode.com/posts/how-to-use-a-env-file-with-python/61b0fe8fccd13f578941ed74/comment/61b192511907c16be2edf80b#reply-61b2e1e79dcafd6aeede344b)

[Lou](https://hashnode.com/@lovelacecoding) Sorry, I don't understand!

Isn't all this is being done by python? why operating system is deciding this behaviour?

(I think it should be case-sensitive because python is a case-sensitive programming language)

[Louëlla Creemers](https://hashnode.com/@lovelacecoding)

[Dec 10, 2021](https://hashnode.com/posts/how-to-use-a-env-file-with-python/61b0fe8fccd13f578941ed74/comment/61b192511907c16be2edf80b#reply-61b3a9103e16b66b1b1e5761)

[Sandeep](https://hashnode.com/@sandeepx21)

You're right about python being case-sensitive.

But these are environment variables, not Python variables. What makes environment variables so easy to work with is that the variables you create in your .env file are saved onto your local OS. When you use os.environ you tell Python that it has to search on your OS for the needed variable, nothing more. Sounds very technical because it is.

Just remember that using uppercase for the variables in your .env file is the easiest way to not get complications if you want someone else to use your code.

[Sandeep](https://hashnode.com/@sandeepx21)

[Dec 11, 2021](https://hashnode.com/posts/how-to-use-a-env-file-with-python/61b0fe8fccd13f578941ed74/comment/61b192511907c16be2edf80b#reply-61b4862db18f1f0c68300c2b)

Thanks [Lou](https://hashnode.com/@lovelacecoding) :)

I think I understand it now

_Just to summarise:_

Some developers came up with an idea to put all imp password/stuff in a file for security and name it as .env

and

this file will (and should) only be available on local machine and the main server (have to upload file seperately) to ensure safety of resources while sharing code

Finally, this article explain how to access those environment variables using python :\]

[Yosra Emad](https://hashnode.com/@yosracodes)

[Dec 8, 2021](https://hashnode.com/posts/how-to-use-a-env-file-with-python/61b0fe8fccd13f578941ed74/comment/61b107196a616156e95e243e)

great post Lou!! it's always important to keep API KEYS safe :D
