A small env file parser
Project description
envfileparser
This package is as simple as possible to get variables from .env files or files with a similar structure.
Description
The package has no dependencies and works with files located in the same directory as the file from which the functions of this package were called.
Function
get_env()
takes the name of the target variable as a string and an optional second parameter - the path to the file. After that, the function returns the value of the variable also as a string.Function
get_envs()
accepts a sequence of variable names as a string, and also an optional parameter-the path to the file. This function returns a list of strings that are the values of the desired variables.By default,
.env
is specified as the path. Empty lines and lines without the'='
character are skipped. In addition, commenting with a prefix of the'#'
character is supported.In the event that the specified variable is missing or the desired file cannot be found, the corresponding exceptions are thrown.
Getting started
Install envfileparser from PyPi with pip: pip install envfileparser
Usage example:
from envfileparser import get_env, get_envs
CONST_ONE = get_env('CONST1')
CONST_TWO = get_env('CONST2', file_path='configs/.env')
variables = get_envs('VAR1', 'VAR2', 'VAR3')
v1, v2, v3 = variables[0], variables[1], variables[2]
Correct .env file example:
# Service token.
API_TOKEN = f3u12yf36f12f418449go3294g238
PORT = 3417
IP = 127.0.0.1 # loopback
USER = 'ADMIN'
PASSWORD="12345678"
If your value contains the " # "character, then be sure to put it in quotation marks-otherwise the parser will take all subsequent characters (including the" # " character) as a comment: The .env file:
VAR1 = envfile#parser
VAR2 = "envfile#parser"
Python code:
from envfileparser import get_env, get_envs
print(*get_envs('VAR1', 'VAR2'), sep='\n')
Output:
envfile
envfile#parser
New version 0.0.6
:
- Added support for comments.
- Skipping empty lines.
- Skipping lines without a character
"="
.
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
Built Distribution
File details
Details for the file envfileparser-0.0.6.tar.gz
.
File metadata
- Download URL: envfileparser-0.0.6.tar.gz
- Upload date:
- Size: 16.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | aca7ae00bc7ca8ccd35693a728d861f447ed3b5f245b68bee1c66f620d62f5b0 |
|
MD5 | ec90ee7f9fc6d18e493f8eb1bfd522c3 |
|
BLAKE2b-256 | e04131563288782cff684651987f88c1af4a8f872d7eb551ccadfb5e3e6c90ce |
File details
Details for the file envfileparser-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: envfileparser-0.0.6-py3-none-any.whl
- Upload date:
- Size: 16.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebd73403d935f94ab3101abfcc55bf812e9dad28ff0c7c7a4f07a18b159b7a6a |
|
MD5 | e4aca7938167ad19a65c735a19b4e023 |
|
BLAKE2b-256 | e81f935b36b6928bfe03e364692e45f447aebbbe2be2d3e8938b450510d3e1fc |