Skip to main content

CLI to create .env files with environment variables.

Project description

Createnv

GitHub Actions: Tests PyPI - Python Version PyPI

A simple CLI to create .env files.

Motivation

I use .env file to decouple configuration from application in many projects, and I see that many newcomers might struggle in creating this file.

Thus, I created this package to offer a better user interface for creating configuration files in the format of .env.

Example

Using the sample .env.sample in this repository:

asciicast

You can now experiment by yourself, or try more advanced .env.sample such as the tests/.env.sample or [Bot Followers's .env.sample]

Install

Createnv requires Python 3.7 or newer:

$ pip install createnv

Usage

To use the default values (reads the sample from .env.sample and write the result into .env):

$ createnv

Options

Option Default Description
--target .env File to write the result
--source .env.sample File to use as a sample
--overwrite and --no-overwrite --no-overwrite Whether to ask before overwriting files
--use-default or --no-use-default --no-use-default Whether to ask for input on fields that have a default value set
--chars-for-random-string All ASCII letters, numbers and a few extra characters (!@#$%^&*(-_=+)) Characters used to create random strings

Format of sample files

Createnv reads the sample file and separate lines in blocks, splitting at empty lines. It follows a few rules:

  1. The first line is required to be a title
  2. The second line might be a description or a variable
  3. The remaining lines should be variables

Title

The first line of the block should start with a # character, followed by a space. The title value is the remaining text after the # and space.

For example:

# Hell Yeah!

In this case, the title is Hell yeah! (not # Hell yeah!).

Description (optional)

If the second line follows the syntax of a title line, it's text (without the # ) is considered a description and is used to give more information to the user about the variables from this block.

Variables

There are three types of variables:

Regular

Each block might one or more variable lines. The syntax requires a name of variable using only capital letters, numbers, or underscore, followed by an equal sign.

What comes after the equal sign is optinal. This text is considered the default value of this variable.

The human description of this variable is also optional. You can create one by using comment at the end of the line. That is to say, any text after a sequence of two spaces, followed by the # sign and one extra space, is the human description of that variable.

For example:

NAME=

This is a valid variable line. It has a name (NAME), no default value, and no human description. We can add a default value:

NAME=Cuducos

This is still a valid variable line. It has a name(NAME), and a default value (Cuducos). Yet, we can add a human description:

NAME=Cuducos  # What is your name?

Now it's a complete variable with a name (NAME), a default value (Cuducos), and a human description (What is your name?)

Random values

If you want to have a variable with a random value, you can set its default value to <random> and Createnv will take care of it. Optionally you can specify how long this variable should be with :int.

For example:

SECRET_KEY=<random>
TOKEN=<random:32>

The first line will create a SECRET_VALUE with random characters and random length (starting at 64 chars).

The second line will create a TOKEN with random value and with exactly 32 characters.

You can use the --chars-for-random-string option to specify which characters to be used.

Auto generated

Finally, you can combine existing variables within the same block to create a new variable (without prompting your user to combine them).

For example, let's say you want to greet someone:

NAME=  # What is your name?
PERIOD=  # Is it morning, afternoon, or evening?
GREETING=Good {PERIOD}, {NAME}!

In this case, Createnv only asks the user for NAME and PERIOD, and creates GREETING automagically.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

createnv-0.0.1.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

createnv-0.0.1-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file createnv-0.0.1.tar.gz.

File metadata

  • Download URL: createnv-0.0.1.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.7.3 Darwin/19.3.0

File hashes

Hashes for createnv-0.0.1.tar.gz
Algorithm Hash digest
SHA256 28dcad8827fe1a2a7e836a86ae0fdfcc4724d7cc6e4ba21536df2fc847516775
MD5 63f33aefb8c25e1eb75c076214873878
BLAKE2b-256 cd82272219814bcfdb4813237152d043cd7f21ddc9d28edea2846480c82450b4

See more details on using hashes here.

File details

Details for the file createnv-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: createnv-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.5 CPython/3.7.3 Darwin/19.3.0

File hashes

Hashes for createnv-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3127c654032cb94442d93572937494d31865c7b3b45dacae415d5e6f418b00c5
MD5 c1512b7f4534b40203c4f2c545dd180d
BLAKE2b-256 a18b320881a9768bc8aff43a27456c661e5755485f631101d04e6049e6069d82

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page