4 releases

0.16.2 Nov 16, 2023
0.16.1 Nov 16, 2023
0.16.0 Nov 11, 2023
0.15.0 May 1, 2023

#1436 in Configuration

Download history 4524/week @ 2025-09-21 2806/week @ 2025-09-28 9102/week @ 2025-10-05 4298/week @ 2025-10-12 7264/week @ 2025-10-19 11110/week @ 2025-10-26 5521/week @ 2025-11-02 4747/week @ 2025-11-09 4153/week @ 2025-11-16 6876/week @ 2025-11-23 6334/week @ 2025-11-30 3601/week @ 2025-12-07 7939/week @ 2025-12-14 2822/week @ 2025-12-21 1953/week @ 2025-12-28 886/week @ 2026-01-04

13,952 downloads per month
Used in razel

MIT license

37KB
919 lines

Crates.io

dotenv-flow.rs

A fork of dotenv-rs that adds support for the popular dotenv-flow loading strategy.

The dotenv-flow strategy works as follows:

  • if a DOTENV_ENV environment variable is set, load .env.{DOTENV_ENV}.local (e.g. .env.staging.local)
  • load .env.local
  • if a DOTENV_ENV environment variable is set, load .env.{DOTENV_ENV} (e.g. .env.staging)
  • load .env

Each step will only load variables that are not already present in the environment, so for example variables in the .env.{DOTENV_ENV}.local file will have the highest priority, followed .env.local and so on.

Breaking in 0.16.0

  • env.{DOTENV_ENV}.local is now loaded before .env.local

HowTo

Installation

cargo add dotenv-flow

Usage

To use this package, add the following line to your main function to load the environment variables from available .env.* files:

fn main() {
  dotenv_flow::dotenv_flow().ok();
}

Tests

To test this project, make sure you pass --test-threads=1 to cargo test, e.g.

cargo test -- --test-threads=1

This is necessary because cargo test runs tests in multiple threads by default, but environment variables are process-globals, therefore we need to limit concurrency to avoid race conditions.

Dependencies

~0–295KB