Name | stringenum JSON |
Version |
0.5.0
JSON |
| download |
home_page | None |
Summary | A small, dependency-free library offering additional enum.StrEnum subclasses and a backport for older Python versions. |
upload_time | 2024-11-22 18:22:41 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.9 |
license | MIT |
keywords |
enum
strenum
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# stringenum
<div align="center">
[![PyPI - Version](https://img.shields.io/pypi/v/stringenum?link=https%3A%2F%2Fpypi.org%2Fproject%2Fstringenum%2F)](https://pypi.org/project/stringenum/)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/stringenum)
![License](https://img.shields.io/github/license/Ravencentric/stringenum)
![Checked with mypy](https://www.mypy-lang.org/static/mypy_badge.svg)
![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)
![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/Ravencentric/stringenum/release.yml)
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ravencentric/stringenum/tests.yml?label=tests)
[![codecov](https://codecov.io/gh/Ravencentric/stringenum/graph/badge.svg?token=812Q3UZG7O)](https://codecov.io/gh/Ravencentric/stringenum)
</div>
## Table Of Contents
* [About](#about)
* [Installation](#installation)
* [Usage](#usage)
* [License](#license)
# About
A small, dependency-free library offering additional [enum.StrEnum](https://docs.python.org/3/library/enum.html#enum.StrEnum) subclasses and a backport for older Python versions.
## Installation
`stringenum` is available on [PyPI](https://pypi.org/project/stringenum/), so you can simply use [pip](https://github.com/pypa/pip) to install it.
```sh
pip install stringenum
```
# Usage
- `stringenum.StrEnum` - A backport of [`enum.StrEnum`](https://docs.python.org/3/library/enum.html#enum.StrEnum). While `StrEnum` was added in Python 3.11, version 3.12 brought changes to the `__contains__` method in `EnumType`, which also impacts `StrEnum`. `stringenum.StrEnum` includes this `__contains__` update from Python 3.12.
- `enum.StrEnum` on Python <=3.11
```py
>>> class Color(enum.StrEnum):
... RED = "RED"
... GREEN = "GREEN"
>>> Color.RED in Color
True
>>> "RED" in Color
Traceback (most recent call last):
...
TypeError: unsupported operand type(s) for 'in': 'str' and 'EnumType'
```
- `enum.StrEnum` on Python >=3.12
```py
>>> class Color(enum.StrEnum):
... RED = "RED"
... GREEN = "GREEN"
>>> Color.RED in Color
True
>>> "RED" in Color
True
>>> 12 in Color
False
```
- `stringenum.StrEnum` on Python >=3.9
```py
>>> class Color(stringenum.StrEnum):
... RED = "RED"
... GREEN = "GREEN"
>>> Color.RED in Color
True
>>> "RED" in Color
True
>>> 12 in Color
False
```
- `stringenum.DuplicateFreeStrEnum` - A subclass of `StrEnum` that ensures all members have unique values and names, raising a `ValueError` if duplicates are found.
```py
>>> class Fruits(DuplicateFreeStrEnum):
... APPLE = "apple"
... BANANA = "banana"
... ORANGE = "apple"
...
Traceback (most recent call last):
...
ValueError: Duplicate values are not allowed in Fruits: <Fruits.ORANGE: 'apple'>
```
- `stringenum.CaseInsensitiveStrEnum` - A subclass of `DuplicateFreeStrEnum` that supports case-insensitive lookup.
```py
>>> class Pet(CaseInsensitiveStrEnum):
... CAT = "meow"
... DOG = "bark"
>>> Pet("Meow")
<Pet.CAT: 'meow'>
>>> Pet("BARK")
<Pet.DOG: 'bark'>
>>> Pet["Cat"]
<Pet.CAT: 'meow'>
>>> Pet["dog"]
<Pet.DOG: 'bark'>
```
- `stringenum.DoubleSidedStrEnum` - A subclass of `DuplicateFreeStrEnum` that supports double-sided lookup, allowing both member values and member names to be used for lookups.
```py
>>> class Status(DoubleSidedStrEnum):
... PENDING = "waiting"
... REJECTED = "denied"
>>> Status("PENDING")
<Status.PENDING: 'waiting'>
>>> Status("waiting")
<Status.PENDING: 'waiting'>
>>> Status["REJECTED"]
<Status.REJECTED: 'denied'>
>>> Status["denied"]
<Status.REJECTED: 'denied'>
```
- `stringenum.DoubleSidedCaseInsensitiveStrEnum` - A subclass of `DuplicateFreeStrEnum` that supports case-insenitive double-sided lookup, allowing both member values and member names to be used for lookups.
```py
>>> class Status(DoubleSidedCaseInsensitiveStrEnum):
... PENDING = "waiting"
... REJECTED = "denied"
>>> Status("pending")
<Status.PENDING: 'waiting'>
>>> Status("Waiting")
<Status.PENDING: 'waiting'>
>>> Status["Rejected"]
<Status.REJECTED: 'denied'>
>>> Status["DenieD"]
<Status.REJECTED: 'denied'>
```
## License
Distributed under the [MIT](https://choosealicense.com/licenses/mit/) License. See [LICENSE](https://github.com/Ravencentric/stringenum/blob/main/LICENSE) for more information.
Raw data
{
"_id": null,
"home_page": null,
"name": "stringenum",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "enum, strenum",
"author": null,
"author_email": "Ravencentric <me@ravencentric.cc>",
"download_url": "https://files.pythonhosted.org/packages/12/74/b32bbcd5279fb2f8d14513a3b30b256603c3988b408f666ac60992c483d3/stringenum-0.5.0.tar.gz",
"platform": null,
"description": "# stringenum\n\n<div align=\"center\">\n\n[![PyPI - Version](https://img.shields.io/pypi/v/stringenum?link=https%3A%2F%2Fpypi.org%2Fproject%2Fstringenum%2F)](https://pypi.org/project/stringenum/)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/stringenum)\n![License](https://img.shields.io/github/license/Ravencentric/stringenum)\n![Checked with mypy](https://www.mypy-lang.org/static/mypy_badge.svg)\n![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)\n\n![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/Ravencentric/stringenum/release.yml)\n![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/ravencentric/stringenum/tests.yml?label=tests)\n[![codecov](https://codecov.io/gh/Ravencentric/stringenum/graph/badge.svg?token=812Q3UZG7O)](https://codecov.io/gh/Ravencentric/stringenum)\n\n</div>\n\n## Table Of Contents\n\n* [About](#about)\n* [Installation](#installation)\n* [Usage](#usage)\n* [License](#license)\n\n# About\n\nA small, dependency-free library offering additional [enum.StrEnum](https://docs.python.org/3/library/enum.html#enum.StrEnum) subclasses and a backport for older Python versions.\n\n## Installation\n\n`stringenum` is available on [PyPI](https://pypi.org/project/stringenum/), so you can simply use [pip](https://github.com/pypa/pip) to install it.\n\n```sh\npip install stringenum\n```\n\n# Usage\n\n- `stringenum.StrEnum` - A backport of [`enum.StrEnum`](https://docs.python.org/3/library/enum.html#enum.StrEnum). While `StrEnum` was added in Python 3.11, version 3.12 brought changes to the `__contains__` method in `EnumType`, which also impacts `StrEnum`. `stringenum.StrEnum` includes this `__contains__` update from Python 3.12.\n\n - `enum.StrEnum` on Python <=3.11\n ```py\n >>> class Color(enum.StrEnum):\n ... RED = \"RED\"\n ... GREEN = \"GREEN\"\n\n >>> Color.RED in Color\n True\n >>> \"RED\" in Color\n Traceback (most recent call last):\n ...\n TypeError: unsupported operand type(s) for 'in': 'str' and 'EnumType'\n ```\n\n - `enum.StrEnum` on Python >=3.12\n ```py\n >>> class Color(enum.StrEnum):\n ... RED = \"RED\"\n ... GREEN = \"GREEN\"\n\n >>> Color.RED in Color\n True\n >>> \"RED\" in Color\n True\n >>> 12 in Color\n False\n ```\n\n - `stringenum.StrEnum` on Python >=3.9\n ```py\n >>> class Color(stringenum.StrEnum):\n ... RED = \"RED\"\n ... GREEN = \"GREEN\"\n\n >>> Color.RED in Color\n True\n >>> \"RED\" in Color\n True\n >>> 12 in Color\n False\n ```\n\n- `stringenum.DuplicateFreeStrEnum` - A subclass of `StrEnum` that ensures all members have unique values and names, raising a `ValueError` if duplicates are found.\n\n ```py\n >>> class Fruits(DuplicateFreeStrEnum):\n ... APPLE = \"apple\"\n ... BANANA = \"banana\"\n ... ORANGE = \"apple\"\n ...\n Traceback (most recent call last):\n ...\n ValueError: Duplicate values are not allowed in Fruits: <Fruits.ORANGE: 'apple'>\n ```\n\n- `stringenum.CaseInsensitiveStrEnum` - A subclass of `DuplicateFreeStrEnum` that supports case-insensitive lookup.\n\n ```py\n >>> class Pet(CaseInsensitiveStrEnum):\n ... CAT = \"meow\"\n ... DOG = \"bark\"\n\n >>> Pet(\"Meow\")\n <Pet.CAT: 'meow'>\n\n >>> Pet(\"BARK\") \n <Pet.DOG: 'bark'>\n\n >>> Pet[\"Cat\"]\n <Pet.CAT: 'meow'>\n\n >>> Pet[\"dog\"] \n <Pet.DOG: 'bark'>\n ```\n\n- `stringenum.DoubleSidedStrEnum` - A subclass of `DuplicateFreeStrEnum` that supports double-sided lookup, allowing both member values and member names to be used for lookups.\n\n ```py\n >>> class Status(DoubleSidedStrEnum):\n ... PENDING = \"waiting\"\n ... REJECTED = \"denied\"\n\n >>> Status(\"PENDING\")\n <Status.PENDING: 'waiting'>\n\n >>> Status(\"waiting\")\n <Status.PENDING: 'waiting'>\n\n >>> Status[\"REJECTED\"]\n <Status.REJECTED: 'denied'>\n\n >>> Status[\"denied\"]\n <Status.REJECTED: 'denied'>\n ```\n\n- `stringenum.DoubleSidedCaseInsensitiveStrEnum` - A subclass of `DuplicateFreeStrEnum` that supports case-insenitive double-sided lookup, allowing both member values and member names to be used for lookups.\n\n ```py\n >>> class Status(DoubleSidedCaseInsensitiveStrEnum):\n ... PENDING = \"waiting\"\n ... REJECTED = \"denied\"\n\n >>> Status(\"pending\")\n <Status.PENDING: 'waiting'>\n\n >>> Status(\"Waiting\")\n <Status.PENDING: 'waiting'>\n\n >>> Status[\"Rejected\"]\n <Status.REJECTED: 'denied'>\n\n >>> Status[\"DenieD\"]\n <Status.REJECTED: 'denied'>\n ```\n\n## License\n\nDistributed under the [MIT](https://choosealicense.com/licenses/mit/) License. See [LICENSE](https://github.com/Ravencentric/stringenum/blob/main/LICENSE) for more information.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A small, dependency-free library offering additional enum.StrEnum subclasses and a backport for older Python versions.",
"version": "0.5.0",
"project_urls": {
"Repository": "https://github.com/Ravencentric/stringenum"
},
"split_keywords": [
"enum",
" strenum"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e6d53c352e2f2260b757309804ee7d14c5aa3c00bb9be64d2d2914adea363335",
"md5": "3db8c1a2bc9ea8431b5e8ca9dfefc998",
"sha256": "3f3541693d9915669f590a3bd12bb00322097d5ce97a363f287618bb9bf48223"
},
"downloads": -1,
"filename": "stringenum-0.5.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3db8c1a2bc9ea8431b5e8ca9dfefc998",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 6129,
"upload_time": "2024-11-22T18:22:40",
"upload_time_iso_8601": "2024-11-22T18:22:40.235260Z",
"url": "https://files.pythonhosted.org/packages/e6/d5/3c352e2f2260b757309804ee7d14c5aa3c00bb9be64d2d2914adea363335/stringenum-0.5.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1274b32bbcd5279fb2f8d14513a3b30b256603c3988b408f666ac60992c483d3",
"md5": "14016f6cbbb25e738dfb06a8324b481b",
"sha256": "c80a702877cf815bb6b15c840d3a97e8994db32e2ac2998dc7e0cf8769632aa1"
},
"downloads": -1,
"filename": "stringenum-0.5.0.tar.gz",
"has_sig": false,
"md5_digest": "14016f6cbbb25e738dfb06a8324b481b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 24266,
"upload_time": "2024-11-22T18:22:41",
"upload_time_iso_8601": "2024-11-22T18:22:41.507837Z",
"url": "https://files.pythonhosted.org/packages/12/74/b32bbcd5279fb2f8d14513a3b30b256603c3988b408f666ac60992c483d3/stringenum-0.5.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-22 18:22:41",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Ravencentric",
"github_project": "stringenum",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "stringenum"
}