Skip to main content

PythonSupport PyPI version

Introduction

General purpose bool/boolean utilities, extracting bools from strings.

Only two so far:

Documentation

📄 Detailed Documentation | 🐍 PyPi

Install

# via pip
pip install xbool

# via poetry
poetry add xbool

Quick Start

bool_value

Generally converts objects to bool-values, special-casing strings to use the built-in distutils.util.strtobool function to convert the string value to a bool.

from xbool import bool_value

# Convert string to bool
assert bool_value('true') is True
assert bool_value('false') is False

assert bool_value('y') is True
assert bool_value('n') is False

assert bool_value('on') is True
assert bool_value('off') is False

assert bool_value('t') is True
assert bool_value('f') is False

assert bool_value('yes') is True
assert bool_value('no') is False

assert bool_value('1') is True
assert bool_value('0') is False

# Any other string is generally considered False:
assert bool_value("some-other-string") is False

# Convert bools to bools:
assert bool_value(True) is True
assert bool_value(False) is False

# Generally, for non-strings, True-like objects return True:
some_object = object()
assert bool_value(some_object) is True

# And False-like objects return False:
assert bool_value(None) is False

bool_env

Looks up environmental variable with passed in name.

Runs the env-var value though bool_value for you and returns the result.

Useful to easily get a bool-value from an environmental variable.

from xbool import bool_env
import os

os.environ['SOME_ENV_VAR'] = "False"
assert bool_env('SOME_ENV_VAR') is False


os.environ['SOME_OTHER_ENV_VAR'] = "True"
assert bool_env('SOME_OTHER_ENV_VAR') is True

Licensing

This library is licensed under the MIT-0 License. See the LICENSE file.

Metadata

Release files for xbool 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xbool 1.1.0
File Size Uploaded
xbool-1.1.0.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for xbool 1.1.0
File Interpreter ABI Platform
xbool-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.5 kB

Release files / xbool-1.1.0.tar.gz

Download URL xbool-1.1.0.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
5c926f6ea07d0c14ba03e087bfce617a3eb99dea1fa1c7987d53e37a030f27ee
BLAKE2b-256 checksum
How to use checksums
a999382bed603cf75ad5fb827c301d5adc4c414020039cb779d819b11e1a9414
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1018-azure

Release files / xbool-1.1.0-py3-none-any.whl

Download URL xbool-1.1.0-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
84e3f4d6873639208c56f5fba70d4f0b66603d0dda80fff788b4fe4262ddc0d2
BLAKE2b-256 checksum
How to use checksums
7a20fce58bcf97dd6ee0f81fcdcb2d1c8a8a302f414e2ad25498ac814360c0eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1018-azure

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

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