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.
Links
- Website — https://lianes8studio.com
- GitHub — https://github.com/JaviLianes8
- LinkedIn — https://www.linkedin.com/in/jlianes/
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)
| File | Size | Uploaded | |
|---|---|---|---|
| boolish-0.1.0.tar.gz | 6.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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
|