An Odin library that loads environment variables from a file.
Add the project as a submodule in the external folder:
git submodule add https://github.com/fatshark-kra/odin-dotenv external/odin-dotenvImport the package:
import dotenv "external/odin-dotenv"Call dotenv.load(".env") as early as possible. You can pass any relative path to the procedure.
Then you can use environment variable functions in the os package.
The library doesn't override variables set outside of the process. For example, assuming DEPLOY_ENV=test in an .env file:
odin run .:// Prints test fmt.println(os.get_env("DEPLOY_ENV"))
DEPLOY_ENV=prod odin run .// Prints prod fmt.println(os.get_env("DEPLOY_ENV"))
This library was built with a recent (late June 2025) master version of Odin, on a Linux system. It is beta software that is confirmed to work on my system. Your mileage may vary and you will likely run into edge cases.