2 unstable releases

0.1.0 Nov 24, 2022
0.0.1 Apr 28, 2022

#292 in Configuration

Download history 3282/week @ 2023-08-03 2391/week @ 2023-08-10 1902/week @ 2023-08-17 2405/week @ 2023-08-24 1755/week @ 2023-08-31 1591/week @ 2023-09-07 1216/week @ 2023-09-14 1840/week @ 2023-09-21 1620/week @ 2023-09-28 1488/week @ 2023-10-05 2609/week @ 2023-10-12 1953/week @ 2023-10-19 1510/week @ 2023-10-26 2084/week @ 2023-11-02 2185/week @ 2023-11-09 3207/week @ 2023-11-16

9,269 downloads per month
Used in 2 crates

MIT license

279 lines


crates.io Released API docs MIT licensed

A correct dotenv library, which supports:

  • Multiline values
  • Variable substitution

Parsing rules

  • BASIC=basic
  • empty lines are skipped
  • lines beginning with # are treated as comments
  • # marks the beginning of a comment (unless when the value is wrapped in quotes)
  • empty values become empty strings
  • inner quotes are maintained
  • whitespace is removed from both ends of unquoted values
  • single and double quoted values are escaped
  • single and double quoted values maintain whitespace from both ends
  • double quoted values expand new lines (MULTILINE="new\nline" becomes
    MULTILINE: "new

Expanding rules

  • $KEY will expand any env with the name KEY
  • ${KEY} will expand any env with the name KEY
  • \$KEY will escape the $KEY rather than expand
  • ${KEY:-default} will first attempt to expand any env with the name KEY. If not one, then it will return default


The easiest and most common usage consists on calling load when the application starts, which will load environment variables from a file named .env in the current directory or any of its parents.

If you need more control about the file name or its location, you can use the from_filename, from_path or from_read.


A .env file looks like this:


You can optionally prefix each line with the word export, which will conveniently allow you to source the whole file on your shell.

A sample project using dotenv would look like this:

fn main() {
    for (key, value) in dotenv::vars() {
        println!("{}: {}", key, value);




~17K SLoC