This project exists for one simple reason: to provide a simple, zero-dependency .env file loader for Python projects.
This is a perfect project for small utility scripts, where you might need to load environment variables but don't want to install any extra deps.
- Copy the contents of
src/main.py, including the full header, to any file in your project. - Somewhere in your script, run the
load_dotenv(path)function. The parameters and requirements differ slightly frompython-dotenv:path: Path to the .env file. type:str | os.PathLike[str]- This is required. I recommend using a
pathlib.Path, but strings work as well. (Technically speaking, any type/class that defines a__fspath__method is compatible)
- This is required. I recommend using a
override_existing: Whether to override existing environment variables. type:bool(default:False)encoding: Encoding to be used to read the file. type:str | None(default:"utf-8")
- Now, you can access environment vars as usual with
os.getenv().
This project has been tested on and should work on Python versions 3.7 and above.
This project is licensed under the MIT License. You are free to use this project how you please, as long as you include the original license text along with the code.