Skip to main content

A simple python module to determine whether an input is True or False.

Project description

true_or_false

A simple python function to determine whether an input is True or False

Determine (educated guess) whether an input value is True or False. Input can be a bool, dict, int or str. This is useful for determining the value of a parameter as passed in via environment variable, cli, config file or plain python code.

Examples of True values: str: ['true', 't', '1', 'yes', 'y', 'oui', '是', 'はい', '예', ...] bool: True dict: {'a': 1} # any non empty dictionary list: [0] # any non-empty list

Examples of False values: str: ['false', 'f', '0', 'no', 'n', 'non', '不', 'いいえ', '아니요', ...] bool: False dict: {} # empty dictionary list: [] # empty list

Supported languages include English, French, German, Spanish, Italian, Russian, Czech, Dutch, Swedish, Hindi, Simplified Chinese, Traditional Chinese, Japanese, and Korean.

Installation

pip install true-or-false

Usage

from true_or_false import true_or_false

b = true_or_false(1)
print(b)
>> True

Optional parameters

true_or_false(s, none_is_false=True, blank_is_false=True)
  • none_is_false — when True (default), None returns False; when False, None returns None
  • blank_is_false — when True (default), a blank string returns False; when False, a blank string returns None

Unrecognized input (a string not in the known lists, or an unsupported type) returns None.

environ_true_or_false

A convenience wrapper that reads an environment variable and interprets its value. Returns None if the variable is unset and no default is provided.

from true_or_false import environ_true_or_false

# Returns True if MY_FLAG is set to 'true', '1', 'yes', etc.
# Returns None if MY_FLAG is not set.
result = environ_true_or_false('MY_FLAG')

# Provide a default in case the variable is not set.
result = environ_true_or_false('MY_FLAG', default=False)

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

true_or_false-0.3.0.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

true_or_false-0.3.0-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file true_or_false-0.3.0.tar.gz.

File metadata

  • Download URL: true_or_false-0.3.0.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.5 Darwin/25.4.0

File hashes

Hashes for true_or_false-0.3.0.tar.gz
Algorithm Hash digest
SHA256 057ed1d3ece84e46a639c2f218998314d92eff5d0178635a6900f6238f1cb19e
MD5 eebcf74e133023fbccc7d11ac399062a
BLAKE2b-256 c5f2b984e0003e336afec064612c552864db12eec241347c293b1719b702f882

See more details on using hashes here.

File details

Details for the file true_or_false-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: true_or_false-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.14.5 Darwin/25.4.0

File hashes

Hashes for true_or_false-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 13bae3ea802c20c6efbe245719fecc14c8bdf75718753c0b4313652e3fb9f5ad
MD5 82a0465c113b17aa10e1a3c42fd4d488
BLAKE2b-256 3442ce9720f70d64e09d086b95b0598bc7ce2b0dc7c47f92718fd69ee0418cf2

See more details on using hashes here.

Supported by

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