ConfigEnv

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
ConfigEnv.dotenvFunction
dotenv(path1, path2, ...; overwrite = true)

dotenv reads .env files from your path, parse their content, merge them together, stores result to ENV, and finally return a EnvProxyDict with the content. If no path argument is given , then .env is used as a default path. During merge procedure, if duplicate keys encountered then value from the rightmost dictionary is used.

By default if key already exists in ENV it is overwritten with the values in .env file. This behaviour can be changed by setting overwrite flag to false or using dual dotenvx function.

Examples

# .env
FOO = bar
USER = john_doe

# julia REPL
# load key-value pairs from ".env", `ENV` duplicate keys are overwritten
julia> ENV["USER"]
user1
julia> cfg = dotenv()
julia> ENV["FOO"]
bar
julia> ENV["USER"]
john_doe
julia> cfg["USER"]
john_doe
source
ConfigEnv.dotenvxMethod
dotenvx(path1, path2, ...; overwrite = false)

dotenvx reads .env files from your path, parse their content, merge them together, stores result to ENV, and finally return a EnvProxyDict with the content. If no path argument is given , then .env is used as a default path. During merge procedure, if duplicate keys encountered then value from the rightmost dictionary is used.

By default if key already exists in ENV it is overwritten with the values in .env file. This behaviour can be changed by setting overwrite flag to true or using dual dotenv function.

Examples

# .env
FOO = bar
USER = john_doe

# julia REPL
# load key-value pairs from ".env", `ENV` duplicate keys are not overwritten
julia> ENV["USER"]
user1
julia> cfg = dotenvx()
julia> ENV["FOO"]
bar
julia> ENV["USER"]
user1
julia> cfg["USER"]
john_doe
source
ConfigEnv.isresolvedMethod
isresolved(cfg::EnvProxyDict)

Returns whether templating procedure was successful or not. Templating can be unsuccessful if there are circular dependencies or templated variables do not exist in the environment.

source
ConfigEnv.parseMethod

ConfigEnv.parse accepts a String or an IOBuffer (any value that can be converted into String), and returns a Dict with the parsed keys and values.

source
ConfigEnv.unresolved_keysMethod
unresolved_keys(cfg::EnvProxyDict)

Returns tuple of circular and undefined keys, where circular are keys which depends on each other and undefined are keys, which use variables that do not exist in the environment.

source