Skip to main content

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

Project description

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.

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

xbool-1.0.1.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

xbool-1.0.1-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file xbool-1.0.1.tar.gz.

File metadata

  • Download URL: xbool-1.0.1.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.6 Linux/5.15.0-1035-azure

File hashes

Hashes for xbool-1.0.1.tar.gz
Algorithm Hash digest
SHA256 44c86c07e221fa3a289fa5d8b477ba2881c34fc4afe24c442159ebf2adaa69b1
MD5 d1ddcd6719fd288414de8c6c3595544f
BLAKE2b-256 2283eeed5fab7b4ecccfcedf853e875a58087585c8fa3722126ff2c2432a3be2

See more details on using hashes here.

File details

Details for the file xbool-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: xbool-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.10.6 Linux/5.15.0-1035-azure

File hashes

Hashes for xbool-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e0ca37ba6f4bdf2d9028406d47cd22cb921cc856e05616e7f586210e67c4de8b
MD5 92cb79d3882b516cf529cc92098ae773
BLAKE2b-256 f721b9b22079128e1ebd5b041782681dce9b9858b8a2581dfedd99323c171b35

See more details on using hashes here.

Supported by

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