Skip to main content

Typed environment variables

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

Copyright ® 2020-2025, 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, 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

Metadata

Release files for envil 0.4.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 envil 0.4.1
File Size Uploaded
envil-0.4.1.tar.gz 14.8 kB Details

Release files / envil-0.4.1.tar.gz

Download URL envil-0.4.1.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ba42b3b7dc0f8c4db7a5faf878ea58674a1eefbf49046e7d5f392fa8ab4250cd
BLAKE2b-256 checksum
How to use checksums
10b72d45b20d06240a46603caa93249d912cb85da5ce84370d905a17536664d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.2

Release history Release notifications | RSS feed

This release

0.4.1 This release

1 release file

0.4.0

1 release file

0.2.0

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.1

1 release file

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