5 releases

0.15.5 Sep 19, 2022
0.15.4 Sep 19, 2022
0.15.3 Aug 30, 2022
0.15.2 Aug 22, 2022
0.15.1 Feb 28, 2022

#7 in Configuration

Download history 1167/week @ 2022-06-14 972/week @ 2022-06-21 1012/week @ 2022-06-28 1478/week @ 2022-07-05 1722/week @ 2022-07-12 2412/week @ 2022-07-19 3939/week @ 2022-07-26 15628/week @ 2022-08-02 24816/week @ 2022-08-09 34238/week @ 2022-08-16 34250/week @ 2022-08-23 44346/week @ 2022-08-30 46325/week @ 2022-09-06 47219/week @ 2022-09-13 51167/week @ 2022-09-20 44683/week @ 2022-09-27

196,473 downloads per month
Used in 135 crates (23 directly)

MIT license

40KB
1K SLoC

dotenvy

crates.io Released API docs

A well-maintained fork of the dotenv crate.

This crate is the suggested alternative for dotenv in security advisory RUSTSEC-2021-0141.

This library loads environment variables from a .env file. This is convenient for dev environments.

The Minimum Supported Rust Version (MSRV) is 1.58.1.

Components

  1. dotenvy crate - A well-maintained fork of the dotenv crate.
  2. dotenvy_macro crate - A macro for compile time dotenv inspection. This is a fork of dotenv_codegen.
  3. dotenvy_codgen_impl crate - Internal implementation for dotenvy_codegen.
  4. dotenvy CLI tool for running a command using the environment from a .env file (currently Unix only)

Usage

Loading at runtime

use dotenvy::dotenv;
use std::env;

fn main() {
    dotenv().ok();

    for (key, value) in env::vars() {
        println!("{key}: {value}");
    }
}

Loading at compile time

The dotenv! macro provided by dotenvy_macro crate can be used.

Warning: there is an outstanding issue with rust-analyzer (rust-analyzer #9606) related to the dotenv! macro

Why does this fork exist?

The original dotenv crate has not been updated since June 26, 2020. Attempts to reach the authors and present maintainer were not successful (dotenv-rs/dotenv #74).

This fork intends to serve as the development home for the dotenv implementation in Rust.

What are the differences from the original?

This repo fixes:

  • home directory works correctly (no longer using the deprecated std::env::home_dir)
  • more helpful errors for dotenv! (dotenv-rs/dotenv #57)

It also adds:

  • multiline support for environment variable values
  • io::Read support via from_read and from_read_iter
  • improved docs

For a full list of changes, refer to the changelog.

The legend

Legend has it that the Lost Maintainer will return, merging changes from dotenvy into dotenv with such thrust that all Cargo.tomls will lose one keystroke. Only then shall the Rust dotenv crateverse be united in true harmony.

Until then, this repo dutifully carries on the dotenv torch. It is actively maintained. Contributions and PRs are very welcome!

Dependencies

~52–560KB