Version 1.1.4 (171 KB) by George
Load environment variables from a .env file.


Updated 16 Mar 2022

From GitHub

View License on GitHub

dotenv for MATLAB

A MATLAB implementation of dotenv

Storing configuration in the environment is one of the tenets of a 12-factor app. dotenv for MATLAB® lets you store configuration data (passwords, API keys, server names, etc.) outside of your code. This lets you share your code without sharing your configuration data.



View dotenv-for-MATLAB on File Exchange


Put dotenv.m somewhere on your search path.

Usage Example

dotenv() will try and load a file named .env from the current working folder. Alternatively, you can specify the path with dotenv('path/to/file.env').


# Obligatory XKCD


d = dotenv();
opts = weboptions('HeaderField', ["accept", "any"; "authorization", d.env.password])
url = ""
response = webread(url, opts);

Common places you may need to do this are weboptions(), working with remote data like S3 buckets, the Database Toolbox, or ftp().


The parsing engine currently supports the following rules:

  • empty lines are skipped
  • lines beginning with # are treated as comments
  • empty values become empty strings (DB_HOST= becomes DBHOST: '')
  • whitespace is removed from both ends of unquoted values (DB_HOST=some server becomes DB_HOST:'some server')
  • quoted values are escaped (DB_PASS=" some password " becomes DB_PASS:' some password ')

Examples are in the config directory.


Should I commit my .env file?

No. You should put *.env in your .gitignore file. MATLAB.gitignore plus *.env is a good start.

Development Setup

Clone the repository. You can run runtests('tests') from the project root to run the unit test suite.


I would love to hear if this breaks on any weird strings or doesn't work the way you expected.

Cite As

George (2023). dotenv-for-MATLAB (, GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2021b
Compatible with R2016b and later releases
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Versions that use the GitHub default branch cannot be downloaded

Version Published Release Notes

See release notes for this release on GitHub:


See release notes for this release on GitHub:


See release notes for this release on GitHub:


Added support for continuous integration through Azure Pipelines and CircleCI


Improved documentation


Updated icon file


To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.