xbool


Namexbool JSON
Version 1.1.0 PyPI version JSON
download
home_pagehttps://github.com/xyngular/py-xbool
SummaryGeneral purpose bool/boolean utilities, extracting bools from strings.
upload_time2023-12-20 18:05:04
maintainer
docs_urlNone
authorJosh Orr
requires_python>=3.10,<4.0
license
keywords bool booltostr str environmental variable utilites
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![PythonSupport](https://img.shields.io/static/v1?label=python&message=%203.10|%203.11|%203.12&color=blue?style=flat-square&logo=python)
![PyPI version](https://badge.fury.io/py/xbool.svg?)

- [Introduction](#introduction)
- [Documentation](#documentation)
- [Install](#install)
- [Quick Start](#quick-start)
    * [bool_value](#bool_value)
    * [bool_env](#bool_env)
- [Licensing](#licensing)

# Introduction

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

Only two so far:

- `bool_value`, see **[bool_value docs](https://xyngular.github.io/py-xbool/latest/)**.
- `bool_env`, see **[bool_env docs](https://xyngular.github.io/py-xbool/latest/)**.

# Documentation

**[📄 Detailed Documentation](https://xyngular.github.io/py-xbool/latest/)** | **[🐍 PyPi](https://pypi.org/project/xbool/)**

# Install

```bash
# 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.

```python
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.

```python
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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/xyngular/py-xbool",
    "name": "xbool",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10,<4.0",
    "maintainer_email": "",
    "keywords": "bool,booltostr,str,environmental variable,utilites",
    "author": "Josh Orr",
    "author_email": "josh@orr.blue",
    "download_url": "https://files.pythonhosted.org/packages/a9/99/382bed603cf75ad5fb827c301d5adc4c414020039cb779d819b11e1a9414/xbool-1.1.0.tar.gz",
    "platform": null,
    "description": "![PythonSupport](https://img.shields.io/static/v1?label=python&message=%203.10|%203.11|%203.12&color=blue?style=flat-square&logo=python)\n![PyPI version](https://badge.fury.io/py/xbool.svg?)\n\n- [Introduction](#introduction)\n- [Documentation](#documentation)\n- [Install](#install)\n- [Quick Start](#quick-start)\n    * [bool_value](#bool_value)\n    * [bool_env](#bool_env)\n- [Licensing](#licensing)\n\n# Introduction\n\nGeneral purpose bool/boolean utilities, extracting bools from strings.\n\nOnly two so far:\n\n- `bool_value`, see **[bool_value docs](https://xyngular.github.io/py-xbool/latest/)**.\n- `bool_env`, see **[bool_env docs](https://xyngular.github.io/py-xbool/latest/)**.\n\n# Documentation\n\n**[\ud83d\udcc4 Detailed Documentation](https://xyngular.github.io/py-xbool/latest/)** | **[\ud83d\udc0d PyPi](https://pypi.org/project/xbool/)**\n\n# Install\n\n```bash\n# via pip\npip install xbool\n\n# via poetry\npoetry add xbool\n```\n\n# Quick Start\n\n## bool_value\n\nGenerally converts objects to bool-values, special-casing strings\nto use the built-in `distutils.util.strtobool` function to convert the string value\nto a bool.\n\n```python\nfrom xbool import bool_value\n\n# Convert string to bool\nassert bool_value('true') is True\nassert bool_value('false') is False\n\nassert bool_value('y') is True\nassert bool_value('n') is False\n\nassert bool_value('on') is True\nassert bool_value('off') is False\n\nassert bool_value('t') is True\nassert bool_value('f') is False\n\nassert bool_value('yes') is True\nassert bool_value('no') is False\n\nassert bool_value('1') is True\nassert bool_value('0') is False\n\n# Any other string is generally considered False:\nassert bool_value(\"some-other-string\") is False\n\n# Convert bools to bools:\nassert bool_value(True) is True\nassert bool_value(False) is False\n\n# Generally, for non-strings, True-like objects return True:\nsome_object = object()\nassert bool_value(some_object) is True\n\n# And False-like objects return False:\nassert bool_value(None) is False\n```\n\n## bool_env\n\nLooks up environmental variable with passed in name.\n\nRuns the env-var value though `bool_value` for you and returns the result.\n\nUseful to easily get a bool-value from an environmental variable.\n\n```python\nfrom xbool import bool_env\nimport os\n\nos.environ['SOME_ENV_VAR'] = \"False\"\nassert bool_env('SOME_ENV_VAR') is False\n\n\nos.environ['SOME_OTHER_ENV_VAR'] = \"True\"\nassert bool_env('SOME_OTHER_ENV_VAR') is True\n```\n\n\n# Licensing\n\nThis library is licensed under the MIT-0 License. See the LICENSE file.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "General purpose bool/boolean utilities, extracting bools from strings.",
    "version": "1.1.0",
    "project_urls": {
        "Homepage": "https://github.com/xyngular/py-xbool",
        "Repository": "https://github.com/xyngular/py-xbool"
    },
    "split_keywords": [
        "bool",
        "booltostr",
        "str",
        "environmental variable",
        "utilites"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7a20fce58bcf97dd6ee0f81fcdcb2d1c8a8a302f414e2ad25498ac814360c0eb",
                "md5": "4834c2cab06d4c33b34b756e59a60b9c",
                "sha256": "84e3f4d6873639208c56f5fba70d4f0b66603d0dda80fff788b4fe4262ddc0d2"
            },
            "downloads": -1,
            "filename": "xbool-1.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4834c2cab06d4c33b34b756e59a60b9c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10,<4.0",
            "size": 4373,
            "upload_time": "2023-12-20T18:05:02",
            "upload_time_iso_8601": "2023-12-20T18:05:02.668235Z",
            "url": "https://files.pythonhosted.org/packages/7a/20/fce58bcf97dd6ee0f81fcdcb2d1c8a8a302f414e2ad25498ac814360c0eb/xbool-1.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a999382bed603cf75ad5fb827c301d5adc4c414020039cb779d819b11e1a9414",
                "md5": "8fe8b4989f2fd341214ae6f7b58e0fd7",
                "sha256": "5c926f6ea07d0c14ba03e087bfce617a3eb99dea1fa1c7987d53e37a030f27ee"
            },
            "downloads": -1,
            "filename": "xbool-1.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "8fe8b4989f2fd341214ae6f7b58e0fd7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10,<4.0",
            "size": 4170,
            "upload_time": "2023-12-20T18:05:04",
            "upload_time_iso_8601": "2023-12-20T18:05:04.545073Z",
            "url": "https://files.pythonhosted.org/packages/a9/99/382bed603cf75ad5fb827c301d5adc4c414020039cb779d819b11e1a9414/xbool-1.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-20 18:05:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "xyngular",
    "github_project": "py-xbool",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "xbool"
}
        
Elapsed time: 0.16040s