caseless-dictionary


Namecaseless-dictionary JSON
Version 2.0.1 PyPI version JSON
download
home_pagehttps://github.com/tybruno/caseless-dictionary
SummaryTyped and Tested Case Insensitive Dictionary which was inspired by Raymond Hettinger
upload_time2024-06-20 21:20:37
maintainerNone
docs_urlNone
authorTyler Bruno
requires_python>=3.6
licenseMIT
keywords python dict dictionary
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/Naereen/StrapDown.js/graphs/commit-activity)
[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-0000ff.svg)](https://github.com/psf/blue)
[![License: MIT](https://img.shields.io/badge/License-MIT-blueviolet.svg)](https://opensource.org/licenses/MIT)
[![codecov](https://codecov.io/gh/tybruno/caseless-dictionary/branch/main/graph/badge.svg?token=ZO94EJFI3G)](https://codecov.io/gh/tybruno/caseless-dictionary)
[![Pylint](https://img.shields.io/badge/Pylint-10.0%2F10-green)](10.0/10)
[![Mypy](https://img.shields.io/badge/Mypy-checked-blue)](10.0/10)

# caseless-dictionary

A simple, fast, typed, and tested implementation for a python3.6+ case-insensitive and attribute case-insensitive 
dictionaries. This class extends and maintains the original functionality of the builtin `dict` while providing extra 
features.

#### Key Features:

* **Easy**: If you don't care about the case of the key in a dictionary then this implementation is easy to use since it
  acts just like a `dict` obj. 
* **Attribute Access**: `CaselessAttrDict` allows attribute-style access to dictionary items, providing an alternative, 
  often more readable way to access dictionary items.
* **Great Developer Experience**: Being fully typed makes it great for editor support.
* **Fully Tested**: Our test suit fully tests the functionality to ensure that `CaselessDict` runs as expected.
* **There is More!!!**:
    * [ModifiableItemsDict](https://github.com/tybruno/modifiable-items-dictionary): CaselessDict is built on top of
      the `ModifiableItemsDict`, which is a library that enables the user to modify the key or/and value of `dict` type
      object at runtime.

## Installation

`pip install caseless-dictionary`

## Caseless Dictionaries

| Class Name           | Description                                                    | Example                                                                      |
|----------------------|----------------------------------------------------------------|------------------------------------------------------------------------------|
| CaselessDict         | A dictionary where keys that are strings are case-folded.      | `CaselessDict({"  HeLLO WoRLD  ": 1})  # Output: {'hello world': 1}`         |
| CaseFoldCaselessDict | A dictionary where keys that are strings are case-folded.      | `CaseFoldCaselessDict({"  HeLLO WoRLD  ": 1})  # Output: {'hello world': 1}` |
| LowerCaselessDict    | A dictionary where keys that are strings are in lower case.    | `LowerCaselessDict({"  HeLLO WoRLD  ": 1})  # Output: {'hello world': 1}`    |
| UpperCaselessDict    | A dictionary where keys that are strings are in upper case.    | `UpperCaselessDict({"  HeLLO WoRLD  ": 1})  # Output: {'HELLO WORLD': 1}`    |
| TitleCaselessDict    | A dictionary where keys that are strings are in title case.    | `TitleCaselessDict({"  HeLLO WoRLD  ": 1})  # Output: {'Hello World': 1}`    |
| SnakeCaselessDict    | A dictionary where keys that are strings are in snake case.    | `SnakeCaselessDict({"  HeLLO WoRLD  ": 1})  # Output: {'hello_world': 1}`    |
| KebabCaselessDict    | A dictionary where keys that are strings are in kebab case.    | `KebabCaselessDict({"  HeLLO WoRLD  ": 1})  # Output: {'hello-world': 1}`    |
| ConstantCaselessDict | A dictionary where keys that are strings are in constant case. | `ConstantCaselessDict({"  HeLLO WoRLD  ": 1})  # Output: {'HELLO_WORLD': 1}` |
## Caseless Attribute Dictionaries

| Class Name               | Description                                                                                                 | Example                                                                     |
|--------------------------|-------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
| SnakeCaselessAttrDict    | A dictionary where keys that are strings are in snake case and can be accessed using attribute notation.    | `SnakeCaselessAttrDict({"  HeLLO WoRLD  ": 1}).hello_world  # Output: 1`    |
| ConstantCaselessAttrDict | A dictionary where keys that are strings are in constant case and can be accessed using attribute notation. | `ConstantCaselessAttrDict({"  HeLLO WoRLD  ": 1}).HELLO_WORLD  # Output: 1` |

### Basic CaselessDict Example

```python
from caseless_dictionary import CaselessDict

# Create a CaselessDict
caseless_dict = CaselessDict({"  HeLLO WoRLD  ": 1, 2: "two"})

print(caseless_dict)  # Output: {'hello world': 1, 2: 'two'}

# Accessing the value using different cases
print(caseless_dict["  hello world  "])  # Output: 1
print(caseless_dict["  HELLO WORLD  "])  # Output: 1

# Accessing non string value
print(caseless_dict[2])  # Output: two
```

### Caseless Dictionary with Key as Str Only

```python
from caseless_dictionary import CaselessDict

# Create a CaselessDict with key_is_str_only set to True
CaselessDict.key_is_str_only = True
caseless_dict = CaselessDict({"  HeLLO WoRLD  ": 1})

# Attempt to set a non-string key
try:
    caseless_dict[1] = 2
except TypeError:
    print("TypeError raised as expected when key_is_str_only is True")
```


### Basic SnakeCaselessAttrDict Example

```python
from caseless_dictionary import SnakeCaselessAttrDict

# Create a SnakeCaselessAttrDict
snake_caseless_attr_dict = SnakeCaselessAttrDict({"  HeLLO WoRLD  ": 1, 2: "two"})
print(snake_caseless_attr_dict)  # Output: {'hello_world': 1, 2: 'two'}

# Accessing the value using attribute notation
print(snake_caseless_attr_dict.hello_world)  # Output: 1
print(snake_caseless_attr_dict.HELLO_WORLD)  # Output: 1

# Accessing the value using Keys
print(snake_caseless_attr_dict["  hello_world  "])  # Output: 1
print(snake_caseless_attr_dict["  HELLO WORLD  "])  # Output: 1

# Accessing non string value
print(snake_caseless_attr_dict[2])  # Output: two

```

### SnakeCaselessAttrDict with Key as Str Only

```python
from caseless_dictionary import SnakeCaselessAttrDict

# Create a SnakeCaselessAttrDict with key_is_str_only set to True
SnakeCaselessAttrDict.key_is_str_only = True
snake_caseless_attr_dict = SnakeCaselessAttrDict({"  HeLLO WoRLD  ": 1})

# Attempt to set a non-string key
try:
    snake_caseless_attr_dict[1] = 2
except TypeError:
    print("TypeError raised as expected when key_is_str_only is True")
```

## Acknowledgments

During the class '(Advanced) Python For Engineers III' taught by [Raymond Hettinger](https://github.com/rhettinger),
Raymond taught us how to inherit from the builtin Python `dict` by creating a Case-insensitive Dict.
I thought this was a wonderful learning experience so I decided to create a project that would build upon what he
taught.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/tybruno/caseless-dictionary",
    "name": "caseless-dictionary",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "python dict dictionary",
    "author": "Tyler Bruno",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/49/21/5df24c479d875e29a450a4d39c9152d4e4a3d50f96f52a2700f824ffefb1/caseless_dictionary-2.0.1.tar.gz",
    "platform": null,
    "description": "[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/Naereen/StrapDown.js/graphs/commit-activity)\n[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-0000ff.svg)](https://github.com/psf/blue)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blueviolet.svg)](https://opensource.org/licenses/MIT)\n[![codecov](https://codecov.io/gh/tybruno/caseless-dictionary/branch/main/graph/badge.svg?token=ZO94EJFI3G)](https://codecov.io/gh/tybruno/caseless-dictionary)\n[![Pylint](https://img.shields.io/badge/Pylint-10.0%2F10-green)](10.0/10)\n[![Mypy](https://img.shields.io/badge/Mypy-checked-blue)](10.0/10)\n\n# caseless-dictionary\n\nA simple, fast, typed, and tested implementation for a python3.6+ case-insensitive and attribute case-insensitive \ndictionaries. This class extends and maintains the original functionality of the builtin `dict` while providing extra \nfeatures.\n\n#### Key Features:\n\n* **Easy**: If you don't care about the case of the key in a dictionary then this implementation is easy to use since it\n  acts just like a `dict` obj. \n* **Attribute Access**: `CaselessAttrDict` allows attribute-style access to dictionary items, providing an alternative, \n  often more readable way to access dictionary items.\n* **Great Developer Experience**: Being fully typed makes it great for editor support.\n* **Fully Tested**: Our test suit fully tests the functionality to ensure that `CaselessDict` runs as expected.\n* **There is More!!!**:\n    * [ModifiableItemsDict](https://github.com/tybruno/modifiable-items-dictionary): CaselessDict is built on top of\n      the `ModifiableItemsDict`, which is a library that enables the user to modify the key or/and value of `dict` type\n      object at runtime.\n\n## Installation\n\n`pip install caseless-dictionary`\n\n## Caseless Dictionaries\n\n| Class Name           | Description                                                    | Example                                                                      |\n|----------------------|----------------------------------------------------------------|------------------------------------------------------------------------------|\n| CaselessDict         | A dictionary where keys that are strings are case-folded.      | `CaselessDict({\"  HeLLO WoRLD  \": 1})  # Output: {'hello world': 1}`         |\n| CaseFoldCaselessDict | A dictionary where keys that are strings are case-folded.      | `CaseFoldCaselessDict({\"  HeLLO WoRLD  \": 1})  # Output: {'hello world': 1}` |\n| LowerCaselessDict    | A dictionary where keys that are strings are in lower case.    | `LowerCaselessDict({\"  HeLLO WoRLD  \": 1})  # Output: {'hello world': 1}`    |\n| UpperCaselessDict    | A dictionary where keys that are strings are in upper case.    | `UpperCaselessDict({\"  HeLLO WoRLD  \": 1})  # Output: {'HELLO WORLD': 1}`    |\n| TitleCaselessDict    | A dictionary where keys that are strings are in title case.    | `TitleCaselessDict({\"  HeLLO WoRLD  \": 1})  # Output: {'Hello World': 1}`    |\n| SnakeCaselessDict    | A dictionary where keys that are strings are in snake case.    | `SnakeCaselessDict({\"  HeLLO WoRLD  \": 1})  # Output: {'hello_world': 1}`    |\n| KebabCaselessDict    | A dictionary where keys that are strings are in kebab case.    | `KebabCaselessDict({\"  HeLLO WoRLD  \": 1})  # Output: {'hello-world': 1}`    |\n| ConstantCaselessDict | A dictionary where keys that are strings are in constant case. | `ConstantCaselessDict({\"  HeLLO WoRLD  \": 1})  # Output: {'HELLO_WORLD': 1}` |\n## Caseless Attribute Dictionaries\n\n| Class Name               | Description                                                                                                 | Example                                                                     |\n|--------------------------|-------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|\n| SnakeCaselessAttrDict    | A dictionary where keys that are strings are in snake case and can be accessed using attribute notation.    | `SnakeCaselessAttrDict({\"  HeLLO WoRLD  \": 1}).hello_world  # Output: 1`    |\n| ConstantCaselessAttrDict | A dictionary where keys that are strings are in constant case and can be accessed using attribute notation. | `ConstantCaselessAttrDict({\"  HeLLO WoRLD  \": 1}).HELLO_WORLD  # Output: 1` |\n\n### Basic CaselessDict Example\n\n```python\nfrom caseless_dictionary import CaselessDict\n\n# Create a CaselessDict\ncaseless_dict = CaselessDict({\"  HeLLO WoRLD  \": 1, 2: \"two\"})\n\nprint(caseless_dict)  # Output: {'hello world': 1, 2: 'two'}\n\n# Accessing the value using different cases\nprint(caseless_dict[\"  hello world  \"])  # Output: 1\nprint(caseless_dict[\"  HELLO WORLD  \"])  # Output: 1\n\n# Accessing non string value\nprint(caseless_dict[2])  # Output: two\n```\n\n### Caseless Dictionary with Key as Str Only\n\n```python\nfrom caseless_dictionary import CaselessDict\n\n# Create a CaselessDict with key_is_str_only set to True\nCaselessDict.key_is_str_only = True\ncaseless_dict = CaselessDict({\"  HeLLO WoRLD  \": 1})\n\n# Attempt to set a non-string key\ntry:\n    caseless_dict[1] = 2\nexcept TypeError:\n    print(\"TypeError raised as expected when key_is_str_only is True\")\n```\n\n\n### Basic SnakeCaselessAttrDict Example\n\n```python\nfrom caseless_dictionary import SnakeCaselessAttrDict\n\n# Create a SnakeCaselessAttrDict\nsnake_caseless_attr_dict = SnakeCaselessAttrDict({\"  HeLLO WoRLD  \": 1, 2: \"two\"})\nprint(snake_caseless_attr_dict)  # Output: {'hello_world': 1, 2: 'two'}\n\n# Accessing the value using attribute notation\nprint(snake_caseless_attr_dict.hello_world)  # Output: 1\nprint(snake_caseless_attr_dict.HELLO_WORLD)  # Output: 1\n\n# Accessing the value using Keys\nprint(snake_caseless_attr_dict[\"  hello_world  \"])  # Output: 1\nprint(snake_caseless_attr_dict[\"  HELLO WORLD  \"])  # Output: 1\n\n# Accessing non string value\nprint(snake_caseless_attr_dict[2])  # Output: two\n\n```\n\n### SnakeCaselessAttrDict with Key as Str Only\n\n```python\nfrom caseless_dictionary import SnakeCaselessAttrDict\n\n# Create a SnakeCaselessAttrDict with key_is_str_only set to True\nSnakeCaselessAttrDict.key_is_str_only = True\nsnake_caseless_attr_dict = SnakeCaselessAttrDict({\"  HeLLO WoRLD  \": 1})\n\n# Attempt to set a non-string key\ntry:\n    snake_caseless_attr_dict[1] = 2\nexcept TypeError:\n    print(\"TypeError raised as expected when key_is_str_only is True\")\n```\n\n## Acknowledgments\n\nDuring the class '(Advanced) Python For Engineers III' taught by [Raymond Hettinger](https://github.com/rhettinger),\nRaymond taught us how to inherit from the builtin Python `dict` by creating a Case-insensitive Dict.\nI thought this was a wonderful learning experience so I decided to create a project that would build upon what he\ntaught.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Typed and Tested Case Insensitive Dictionary which was inspired by Raymond Hettinger",
    "version": "2.0.1",
    "project_urls": {
        "Homepage": "https://github.com/tybruno/caseless-dictionary"
    },
    "split_keywords": [
        "python",
        "dict",
        "dictionary"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b25d61721b5011ed53fdb7e86146a01135cdc1a68df67319fcc969c5c157fc41",
                "md5": "b64055689c352c7ad5dfc5854555b602",
                "sha256": "ca962b27d48289b5533c31f5bd2f65677a4ffc00ab7934cd2ee969380e38516e"
            },
            "downloads": -1,
            "filename": "caseless_dictionary-2.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b64055689c352c7ad5dfc5854555b602",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 8975,
            "upload_time": "2024-06-20T21:20:33",
            "upload_time_iso_8601": "2024-06-20T21:20:33.835662Z",
            "url": "https://files.pythonhosted.org/packages/b2/5d/61721b5011ed53fdb7e86146a01135cdc1a68df67319fcc969c5c157fc41/caseless_dictionary-2.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "49215df24c479d875e29a450a4d39c9152d4e4a3d50f96f52a2700f824ffefb1",
                "md5": "ebfe3f4fc1456edb4d2f4f8823af708c",
                "sha256": "34f31ab1651424fe939aa1d9de03870f4e24b89456e7a936705ef17560d945e5"
            },
            "downloads": -1,
            "filename": "caseless_dictionary-2.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "ebfe3f4fc1456edb4d2f4f8823af708c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 12200,
            "upload_time": "2024-06-20T21:20:37",
            "upload_time_iso_8601": "2024-06-20T21:20:37.247993Z",
            "url": "https://files.pythonhosted.org/packages/49/21/5df24c479d875e29a450a4d39c9152d4e4a3d50f96f52a2700f824ffefb1/caseless_dictionary-2.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-20 21:20:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "tybruno",
    "github_project": "caseless-dictionary",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "caseless-dictionary"
}
        
Elapsed time: 1.06816s