Mojo-dotenv v0.2.0 - Load .env files in Mojo (98%+ python-dotenv compatible)

# mojo-dotenv :fire:

I’m excited to share **mojo-dotenv v0.2.0** - a modern `.env` file parser and loader for Mojo!

## What is it?

Load environment variables from `.env` files into your Mojo applications.

from dotenv import load_dotenv, dotenv_values, find_dotenv

from os import getenv

fn main() raises:

# Option 1: Load into environment

\_ = load_dotenv(".env")

print(getenv(“DATABASE_URL”))

# Option 2: Parse to Dict

var config = dotenv_values(“.env”)

print(config[“API_KEY”])

# Option 3: Auto-discover .env file

var env_path = find_dotenv()

\_ = load_dotenv(env_path)

## Features

:white_check_mark: **Parse .env files** - `dotenv_values()` returns `Dict[String, String]`

:white_check_mark: **Load into environment** - `load_dotenv()` sets environment variables

:white_check_mark: **Variable expansion** - `${VAR}` and `$VAR` syntax supported

:white_check_mark: **Multiline values** - Quoted strings can span multiple lines

:white_check_mark: **Escape sequences** - `\n`, `\t`, `\"`, `\\`, `\'` in quoted strings

:white_check_mark: **Auto-discovery** - `find_dotenv()` searches parent directories

:white_check_mark: **98%+ python-dotenv compatible** - Validated with comprehensive test suite

:white_check_mark: **Modern Mojo** - Built for Mojo 2025/2026 with latest syntax

:white_check_mark: **42 comprehensive tests** - Using Mojo’s TestSuite framework

:white_check_mark: **Multiple installation methods** - Git submodule, source copy, or .mojopkg

## Why?

- Separate configuration from code

- Different configs for dev/staging/prod

- Keep secrets out of version control

- Standard practice in Python, Node, Ruby ecosystems

- Now available in Mojo!

## Acknowledgments

This project builds on:

- **python-dotenv** - Reference implementation and compatibility target

- **mojoenv** by itsdevcoffee - Pioneer of .env in Mojo (2023), inspired this modern rewrite

**License**: MIT License

## Feedback Most Welcome!

This is a community project - PRs, issues, and feedback welcome!

- Repo: GitHub - DataBooth/mojo-dotenv: Modern .env file parser and loader for Mojo with 98%+ python-dotenv compatibility

- Issues: GitHub · Where software is built

Let me know if you use it in your projects! :rocket:

6 Likes

A blog post about my development of this package:
https://www.databooth.com.au/posts/mojo/building-mojo-dotenv/

This is super cool, congratulations!

thanks Chris (encouragement is such a powerful good)

Have also submitted mojo-toml :slight_smile: