Skip to main content

Get non-string values from environment variables.

Project description

Typed environment variables

This module implements the mundane task of getting typed values from environment variables.

Copyright ® 2020, Luís Gomes luismsgomes@gmail.com. All rights reserved.

Links: https://github.com/luismsgomes/envil | https://pypi.org/project/envil/

Usage

Assuming your environment has two variables set as follows (bash syntax):

export FOO=123
export BAR=y

Then, you may access them in Python code as follows:

import envil as env

foo = env.get_int("FOO", 0)
bar = env.get_bool("BAR", False)

The set of strings considered to be falsy values for boolean variables are specified in envil.FALSY_VALUES:

>>> print(repr(envil.FALSY_VALUES))
{"0", "false", "f", "no", "n"}

If needed you may override this list with your own, as in this example:

bar = env.get_bool("BAR", falsy_strings={"nope", "zilch", "zero", "nada"})

The second argument is the default value to be returned if the variable is not defined. If not specified, this argument will default to envil.RAISE_EXCEPTION, which will cause an EnvironmentVariableNotSet exception to be raised if the variable is not defined.

Note that, unlike in Python's getenv(), you may specify None as a valid default value.

License

This library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 3 as published by the Free Software Foundation.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for more details.

You should have received a copy of the GNU General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

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

envil-0.1.1.tar.gz (2.4 kB view details)

Uploaded Source

File details

Details for the file envil-0.1.1.tar.gz.

File metadata

  • Download URL: envil-0.1.1.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.50.0 CPython/3.7.7

File hashes

Hashes for envil-0.1.1.tar.gz
Algorithm Hash digest
SHA256 783958152c1aa862a6e03eddf6591b61769cb9bfc78443526b3ed059a4509f2d
MD5 c28613c2cd35224712cd2b6ca720c33d
BLAKE2b-256 565395b443ec6f1db1e771da05318286f8f09c34f4b2a619b4a5edca490bdeb8

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