Skip to main content

envio

Environment variable parser library for python.

Mostly created as a reference for how basic package creation works. Many similar projects exist; the goal of this one to make the most basic implementation possible and also establish the minimum amount of boilerplate to create a package for submission.

Installation

run pip install envio

Usage

Basic usage

import envio

# Fetch the envirnment variable MYARG and use value 'yay' if not found
MYARG = envio.get_var('MYARG', default='yay')

# If a default is not specified, then an exception will be raised if the
# environment variable does not exist. This is how we can specify required
# variables.
MYARG = envio.get_var('MYARG') # MYARG is required

Environment variables can also be coerced into multiple different types

# coerce required variable MYINT into an integer
MYINT = envio.get_var('MYINT', var_type=int)

MYFLOAT = envio.get_var('MYFLOAT', var_type=float)

# Acceptable inputs for boolean values include:
# case insensitive versions of 'true' and 'false'
# case insensitive words 'on' and 'off'
# '1' and '0'
# case insensitive letters 't' and 'f'
MYBOOL = envio.get_var('MYBOOL', var_type=bool)

# Dictionaries are also supported but require the environment variable to be
# a valid json string. Below is an example of how to specify a simple dict
# through a json string.
MYDICT = envio.get_var('MYDICT', var_type='json', default='{"hello": "world"}')

Variables can also be coerced into lists by using the many=True argument.

# e.g MYLIST <-- '1,hello, 7, 12.0'
# the following will parse as
# MYLIST = ['1', 'hello', '7', '12.0']
MYLIST = envio.get_var('MYLIST', many=True)

# list parsing can be combined with type coercion. This will enforce that
# every member of the list be parsed as 'var_type'.
MYINTS = envio.get_var('MYINTS', var_type=int, many=True)

# The delimmiter used for parsing lists defaults to a comma, but it can be
# changed with an optional 'delimmiter' param.
MYINTS = envio.get_var('MYINTS', var_type=int, many=True, delimmiter='||', default='1||2||3')

# using 'var_type'=json also allows the parsing of integers, lists of integers
# and the like. It allows mixed types in lists and should be used carefully.
# the example below will produce [1, 2, '3']
MYLIST = envio.get_var('MYLIST', var_type='json', default='[1, 2, "3"]')

Default values can only be STRING values. This is done so that even the default value we choose has to go through the same parser as if we had gotten it as an environment variable. This avoids a class of errors where an incompatible default can be chosen. e.g. expecting a integer but defaulting to a boolean.

# this is the correct way to specify a default for a list of integers
MYINTS = envio.get_var('MYINTS', var_type=int, many=True, default='1,2,3')

Development

You'll want to clone the package somewhere and have either pipenv or virtualenv available on your environment.

A Pipfile is included in this project. It comes mostly with packages used to run twine - the utility used to submit packages to pypi. It can also be used to install this project's distributions locally.

All commands assume the working directory is the repo root.

# install a virtual env and the pipfile requirements.
pipenv install
# activate the virtualenv in the shell. All commands should be run after this
# activation
pipenv shell

# builds can be generated like so:
python setup.py sdist bdist_wheel

# builds can then be submitted to pypi using twine like so:

# upload to test pypi
twine upload --repository-url  https://test.pypi.org/legacy/ dist/*

# upload to the actual pypi servers.
twine upload --repository-url  https://upload.pypi.org/legacy/ dist/*

# tests can be run using setup.py as well
python setup.py test

Metadata

Release files for envio 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for envio 1.0.1
File Size Uploaded
envio-1.0.1.tar.gz 5.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for envio 1.0.1
File Interpreter ABI Platform
envio-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.6 kB

Release files / envio-1.0.1.tar.gz

Download URL envio-1.0.1.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
51f2ebfdb3d8af69af0fc89d83d936caf4152c5b1773aec6c9620e810cd5c807
BLAKE2b-256 checksum
How to use checksums
65f4631c3555a77155c73ccc9d6646abcd944119b358f60ac56692a0c8691a7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.4

Release files / envio-1.0.1-py3-none-any.whl

Download URL envio-1.0.1-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3310517553f4d208cb17bdb9b0435e964c603dc0351e77ff35ee165da0a8dfef
BLAKE2b-256 checksum
How to use checksums
3c9f5105b1565c4bf6d63d8b6b555cffcec2ab1e957463e8aefe91c6c02e28ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.25.0 CPython/3.6.4

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page