/ConfigEnv.jl

Package for populating ENVironment variables.

Primary LanguageJuliaOtherNOASSERTION

ConfigEnv

Documentation Build Status JuliaHub
StableDev BuildCoverage pkgevalversion

ConfigEnv.jl is an environment configuration package that loads environment variables from a .env file into ENV. This package was inspired by python-dotenv library and the Twelve-Factor App methodology.

It's intended usage is when you have some secrets like database passwords, which shouldn't leak into public space and at the same time you want to have simple and flexible management of such secrets. Another usage possibility is when some library uses environmental variables for configuration and you want to configure them without editing your .bashrc or Windows environment.

Installation

ConfigEnv.jl is a registered package, so it can be installed with

julia> using Pkg; Pkg.add("ConfigEnv")

or

# switch to pkg mode
julia> ] 
v1.6> add ConfigEnv

Usage

Create a .env file in your project. You can add environment-specific variables using the rule NAME=VALUE. For example:

#.env file
USER = foo
PASSWORD = bar

Usually it is a good idea to put this file into your .gitignore file, so secrets wouldn't leak to the public space. After that you can use it in your application

using ConfigEnv

dotenv() # loads environment variables from .env

This way ENV obtains key values pairs you set in your .env file.

julia> ENV["PASSWORD"]
"bar"

Features

ConfigEnv.jl provides following features in order to make environment configuration more flexible

  • load data from configuration files to ENV in overwriting and non overwriting mode;
  • reading data from String and IO objects;
  • merging data from different configuration files;
  • templating variables with an arbitrary templating depth and introspection tools for discovering unresolved templates and circular dependencies.