str2bool

1.1 · maintenance · verified Thu Apr 16

This library provides a simple function to convert string representations to boolean values. It explicitly recognizes 'yes', 'true', 'y', 't', '1' as True, and 'no', 'false', 'n', 'f', '0' as False, with case-insensitivity. This version (1.1) was released in 2017 and is currently in maintenance mode with no active development.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates importing the `str2bool` function and converting various string inputs. Unrecognized strings default to `False`.

from str2bool import str2bool

# Example usage
print(f"'Yes' -> {str2bool('Yes')}")
print(f"'no' -> {str2bool('no')}")
print(f"'1' -> {str2bool('1')}")
print(f"'FALSE' -> {str2bool('FALSE')}")
print(f"'invalid_string' -> {str2bool('invalid_string')}") # Returns False by default for unrecognized strings

view raw JSON →