All Projects → theskumar → Python Dotenv

theskumar / Python Dotenv

Licence: other
Get and set values in your .env file in local and production servers. 🎉

Programming Languages

python
139335 projects - #7 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to Python Dotenv

Envkey App
Secure, human-friendly, cross-platform secrets and config.
Stars: ✭ 83 (-98.17%)
Mutual labels:  configuration-management, devops-tools
envkey-python
EnvKey's python library. Protect API keys and credentials. Keep configuration in sync.
Stars: ✭ 24 (-99.47%)
Mutual labels:  configuration-management, devops-tools
ini
📝 Go INI config management. support multi file load, data override merge. parse ENV variable, parse variable reference. Dotenv file parse and loader. INI配置读取管理,支持多文件加载,数据覆盖合并, 解析ENV变量, 解析变量引用。DotEnv 解析加载
Stars: ✭ 72 (-98.41%)
Mutual labels:  dotenv, configuration-management
Chef Plugin
This is jenkins plugin to run chef-client on remote host
Stars: ✭ 38 (-99.16%)
Mutual labels:  configuration-management, devops-tools
node
💪 Simple & Secure Config Management for Node.js 💪
Stars: ✭ 32 (-99.29%)
Mutual labels:  dotenv, configuration-management
hesperides
Configuration management tool providing universal text file templating and properties editing through a REST API or a webapp (backend part)
Stars: ✭ 35 (-99.23%)
Mutual labels:  backend, configuration-management
superconfig
Access environment variables. Also includes presence validation, type coercion and default values.
Stars: ✭ 33 (-99.27%)
Mutual labels:  dotenv, configuration-management
envkey-node
EnvKey's official Node.js client library
Stars: ✭ 46 (-98.99%)
Mutual labels:  configuration-management, devops-tools
devops-notes
My technical documentation in the SRE / DevOps paradigm.
Stars: ✭ 19 (-99.58%)
Mutual labels:  configuration-management, devops-tools
efs2
A dead-simple configuration management tool powered by stupid shell scripts.
Stars: ✭ 82 (-98.19%)
Mutual labels:  configuration-management, devops-tools
nest-typed-config
Intuitive, type-safe configuration module for Nest framework ✨
Stars: ✭ 47 (-98.96%)
Mutual labels:  dotenv, configuration-management
envkey-ruby
EnvKey's official Ruby client library
Stars: ✭ 24 (-99.47%)
Mutual labels:  configuration-management, devops-tools
envkeygo
EnvKey's official Go client library
Stars: ✭ 36 (-99.21%)
Mutual labels:  configuration-management, devops-tools
Conf
Конспекты докладов IT-конференций
Stars: ✭ 365 (-91.95%)
Mutual labels:  backend
Web Skills
A visual overview of useful skills to learn as a web developer
Stars: ✭ 5,107 (+12.66%)
Mutual labels:  backend
Icingaweb2 Module Director
The Director aims to be your new favourite Icinga config deployment tool. Director is designed for those who want to automate their configuration deployment and those who want to grant their “point & click” users easy access to the configuration.
Stars: ✭ 359 (-92.08%)
Mutual labels:  configuration-management
Xbackbone
A lightweight file manager with full ShareX, Screencloud support and more
Stars: ✭ 359 (-92.08%)
Mutual labels:  backend
Conform
Easy, powerful, and extendable configuration tooling for releases.
Stars: ✭ 384 (-91.53%)
Mutual labels:  configuration-management
Visidata
A terminal spreadsheet multitool for discovering and arranging data
Stars: ✭ 4,606 (+1.61%)
Mutual labels:  devops-tools
Lxdock
Build and orchestrate your development environments with LXD - a.k.a. Vagrant is Too Heavy™
Stars: ✭ 350 (-92.28%)
Mutual labels:  devops-tools

python-dotenv

Build Status PyPI version

Python-dotenv reads key-value pairs from a .env file and can set them as environment variables. It helps in the development of applications following the 12-factor principles.

Getting Started

pip install python-dotenv

If your application takes its configuration from environment variables, like a 12-factor application, launching it in development is not very practical because you have to set those environment variables yourself.

To help you with that, you can add Python-dotenv to your application to make it load the configuration from a .env file when it is present (e.g. in development) while remaining configurable via the environment:

from dotenv import load_dotenv

load_dotenv()  # take environment variables from .env.

# Code of your application, which uses environment variables (e.g. from `os.environ` or
# `os.getenv`) as if they came from the actual environment.

By default, load_dotenv doesn't override existing environment variables.

To configure the development environment, add a .env in the root directory of your project:

.
├── .env
└── foo.py

The syntax of .env files supported by python-dotenv is similar to that of Bash:

# Development settings
DOMAIN=example.org
ADMIN_EMAIL=admin@${DOMAIN}
ROOT_URL=${DOMAIN}/app

If you use variables in values, ensure they are surrounded with { and }, like ${DOMAIN}, as bare variables such as $DOMAIN are not expanded.

You will probably want to add .env to your .gitignore, especially if it contains secrets like a password.

See the section "File format" below for more information about what you can write in a .env file.

Other Use Cases

Load configuration without altering the environment

The function dotenv_values works more or less the same way as load_dotenv, except it doesn't touch the environment, it just returns a dict with the values parsed from the .env file.

from dotenv import dotenv_values

config = dotenv_values(".env")  # config = {"USER": "foo", "EMAIL": "[email protected]"}

This notably enables advanced configuration management:

import os
from dotenv import dotenv_values

config = {
    **dotenv_values(".env.shared"),  # load shared development variables
    **dotenv_values(".env.secret"),  # load sensitive variables
    **os.environ,  # override loaded values with environment variables
}

Parse configuration as a stream

load_dotenv and dotenv_values accept streams via their stream argument. It is thus possible to load the variables from sources other than the filesystem (e.g. the network).

from io import StringIO

from dotenv import load_dotenv

config = StringIO("USER=foo\n[email protected]")
load_dotenv(stream=config)

Load .env files in IPython

You can use dotenv in IPython. By default, it will use find_dotenv to search for a .env file:

%load_ext dotenv
%dotenv

You can also specify a path:

%dotenv relative/or/absolute/path/to/.env

Optional flags:

  • -o to override existing variables.
  • -v for increased verbosity.

Command-line Interface

A CLI interface dotenv is also included, which helps you manipulate the .env file without manually opening it.

$ pip install "python-dotenv[cli]"
$ dotenv set USER foo
$ dotenv set EMAIL [email protected]
$ dotenv list
USER=foo
[email protected]
$ dotenv run -- python foo.py

Run dotenv --help for more information about the options and subcommands.

File format

The format is not formally specified and still improves over time. That being said, .env files should mostly look like Bash files.

Keys can be unquoted or single-quoted. Values can be unquoted, single- or double-quoted. Spaces before and after keys, equal signs, and values are ignored. Values can be followed by a comment. Lines can start with the export directive, which has no effect on their interpretation.

Allowed escape sequences:

  • in single-quoted values: \\, \'
  • in double-quoted values: \\, \', \", \a, \b, \f, \n, \r, \t, \v

Multiline values

It is possible for single- or double-quoted values to span multiple lines. The following examples are equivalent:

FOO="first line
second line"
FOO="first line\nsecond line"

Variable expansion

Python-dotenv can interpolate variables using POSIX variable expansion.

With load_dotenv(override=True) or dotenv_values(), the value of a variable is the first of the values defined in the following list:

  • Value of that variable in the .env file.
  • Value of that variable in the environment.
  • Default value, if provided.
  • Empty string.

With load_dotenv(override=False), the value of a variable is the first of the values defined in the following list:

  • Value of that variable in the environment.
  • Value of that variable in the .env file.
  • Default value, if provided.
  • Empty string.

Related Projects

Acknowledgements

This project is currently maintained by Saurabh Kumar and Bertrand Bonnefoy-Claudet and would not have been possible without the support of these awesome people.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].