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— whenTrue(default),NonereturnsFalse; whenFalse,NonereturnsNoneblank_is_false— whenTrue(default), a blank string returnsFalse; whenFalse, a blank string returnsNone
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)
Metadata
Release files for true_or_false 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| true_or_false-0.3.0.tar.gz | 3.4 kB | Without provenance | Details for true_or_false-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| true_or_false-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for true_or_false-0.3.0-py3-none-any.whl |
Total release size: 8.0 kB
Release files / true_or_false-0.3.0.tar.gz
| Download URL | true_or_false-0.3.0.tar.gz |
|---|---|
| Size | 3.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
057ed1d3ece84e46a639c2f218998314d92eff5d0178635a6900f6238f1cb19e
|
|
BLAKE2b-256 checksum How to use checksums |
c5f2b984e0003e336afec064612c552864db12eec241347c293b1719b702f882
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.14.5 Darwin/25.4.0
|
Release files / true_or_false-0.3.0-py3-none-any.whl
| Download URL | true_or_false-0.3.0-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
13bae3ea802c20c6efbe245719fecc14c8bdf75718753c0b4313652e3fb9f5ad
|
|
BLAKE2b-256 checksum How to use checksums |
3442ce9720f70d64e09d086b95b0598bc7ce2b0dc7c47f92718fd69ee0418cf2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.4.1 CPython/3.14.5 Darwin/25.4.0
|
Security for true_or_false 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.