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.2.0.tar.gz (3.1 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.2.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: true_or_false-0.2.0.tar.gz
  • Upload date:
  • Size: 3.1 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.2.0.tar.gz
Algorithm Hash digest
SHA256 1abd0ed52467b39e0cae7cafc57c50974e45bb0c5d1193a40cb4e62abcaea1e9
MD5 8f02a2407b79447646c73c0f665b4602
BLAKE2b-256 788b7942a4a90939726d479a15849348b379b90d2feb1726d6490dbf3a9a5bbb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: true_or_false-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.3 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 505f9fcc79b4fe708d4f693c10b5fa91b7ed45e4b37ae8a8d378178c659f867f
MD5 ff5e7fedf755fe306be50bd4353eca43
BLAKE2b-256 56d11304161f7888d51420d6ffd8caebc721980153a07a769976cef4b3e6d13b

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