Norvie
Norvie8mo ago

Reading env file

Hi guys, rookie question perhaps. I am having trouble reading the contents of a .env file where I store an API key with marimo, VSCode seems to be able to read contents of the same file. I also cant see the file in the files view, but it is in the same directory
4 Replies
Myles Scolnick
Myles Scolnick8mo ago
You should be able to read the file fine. How are you reading it? For the file explorer, I chose to hide dotfiles, but I can see why an env file would be nice to see. I’ll update that
Norvie
NorvieOP8mo ago
Hey Myles! thanks for the quick response This is my current setup import os from dotenv import load_dotenv load_dotenv() openai.api_key = os.getenv("OPENAI_API_KEY") and the .env file has one line: OPENAI_API_KEY=xxxxxxxxxx if I try to print openai.api_key it shows None 🙂
Myles Scolnick
Myles Scolnick8mo ago
ah, for load_dotenv:
The package dotenv’s loadenv() function does not work out-of-the box in marimo. Instead, use dotenv.load_dotenv(dotenv.find_dotenv(usecwd=True)).
here is the FAQ (https://docs.marimo.io/faq.html#how-do-i-use-dotenv)
Norvie
NorvieOP8mo ago
Awesome, thanks again Myles! great project and wish you guys best of luck!