7 releases

0.15.7 Mar 22, 2023
0.15.6 Oct 17, 2022
0.15.5 Sep 19, 2022
0.15.3 Aug 30, 2022
0.15.1 Feb 28, 2022

#2 in Configuration

Download history 247885/week @ 2024-01-02 265428/week @ 2024-01-09 279738/week @ 2024-01-16 271921/week @ 2024-01-23 274100/week @ 2024-01-30 270483/week @ 2024-02-06 259944/week @ 2024-02-13 270724/week @ 2024-02-20 285947/week @ 2024-02-27 293687/week @ 2024-03-05 287178/week @ 2024-03-12 277488/week @ 2024-03-19 270152/week @ 2024-03-26 294870/week @ 2024-04-02 289744/week @ 2024-04-09 249226/week @ 2024-04-16

1,156,391 downloads per month
Used in 1,047 crates (326 directly)

MIT license

49KB
1K SLoC

dotenvy

Crates.io msrv 1.56.1 ci 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.

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 CLI tool for running a command using the environment from a .env file (currently Unix only)

Usage

Loading at runtime

use std::env;
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>> {
    // Load environment variables from .env file.
    // Fails if .env file not found, not readable or invalid.
    dotenvy::dotenv()?;

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

    Ok(())
}

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

Minimum supported Rust version

Currently: 1.56.1

We aim to support the latest 8 rustc versions - approximately 1 year. Increasing MSRV is not considered a semver-breaking change.

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:

It also adds:

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

~230KB