from typing import Any


def as_kafka_configuration_bool(value: Any) -> bool:
    """
    Convert a value to a Python boolean, using the same conversions used by
    the librdkafka configuration parser.
    """
    # https://github.com/edenhill/librdkafka/blob/c8293af/src/rdkafka_conf.c#L1633-L1660
    if isinstance(value, str):
        value = value.lower()
        if value in {"true", "t", "1"}:
            return True
        elif value in {"false", "f", "0"}:
            return False
        else:
            raise ValueError(f"cannot interpret {value!r} as boolean")
    elif isinstance(value, bool):
        return value
    elif isinstance(value, int):
        if value == 1:
            return True
        elif value == 0:
            return False
        else:
            raise ValueError(f"cannot interpret {value!r} as boolean")

    raise TypeError(f"cannot interpret {value!r} as boolean")