Reinventing the wheel to load .env variables
- Python version:
>= 3.9
pip install loadotenv
From a .py
file near your .env
file:
from loadotenv import load_env
load_env()
# load_env(file_loc="/loc/to/.env")
For a flexible usage, use pathlib.Path
when locating your .env
file.
from pathlib import Path
from loadotenv import load_env
load_env(file_loc=Path(Path(__file__).resolve().parent, ".env"))
Issues and PRs are welcome!