Skip to main content

boolish

Parse a string into a boolean. A typed, dependency-free stand-in for distutils.util.strtobool, which was removed from the standard library in Python 3.12.

Install

pip install boolish

Usage

from boolish import strtobool

strtobool("yes")     # True
strtobool("Off")     # False
strtobool("  1 ")    # True  (space and case are ignored)
strtobool("maybe")   # ValueError

Give a default to get it back instead of an error:

strtobool("maybe", False)   # False

Read a flag straight from the environment. A missing variable falls back to the default; a set-but-nonsense value raises, so a misconfigured flag fails loudly:

from boolish import getenv_bool

getenv_bool("ENABLE_CACHE", False)

Bring your own vocabulary:

from boolish import BoolRules, strtobool

spanish = BoolRules(true={"sí", "verdadero"}, false={"no", "falso"})
strtobool("SÍ", rules=spanish)   # True

Why

The standard library's strtobool was the quiet default for reading boolean flags and environment variables. It was deprecated in 3.10 and removed in 3.12, and the dedicated packages that filled the gap have gone unmaintained for years. This is the same idea, kept small: real bool results, type hints, no dependencies, and the environment helper most projects ended up writing by hand.

License

MIT — see LICENSE.

Metadata

Release files for boolish 0.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 boolish 0.1.0
File Size Uploaded
boolish-0.1.0.tar.gz 6.2 kB Details

Built distribution (wheel)

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

Total release size: 11.4 kB

Release files / boolish-0.1.0.tar.gz

Download URL boolish-0.1.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
963ef8a646dc2fc62530f73f975016c79391c777ce3cf8539fc86a6a6e802bd4
BLAKE2b-256 checksum
How to use checksums
6f63b189ede51a45c985b7e4120cc95f2456916feb4656877611cab3d698e4d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release files / boolish-0.1.0-py3-none-any.whl

Download URL boolish-0.1.0-py3-none-any.whl
Size 5.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d702d28bc8d94da421538ee8eb13e14ad8ca16f5f2f46f3456b124b3c8a3b48b
BLAKE2b-256 checksum
How to use checksums
6536101e857139cb5c048840f47ffeb8a65fa374c11911d331ba95a8e43645a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release history Release notifications | RSS feed

This release

0.1.0 This release

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