A small, dependency-free library offering additional enum.StrEnum subclasses and a backport for older Python versions.
Project description
stringenum
Table Of Contents
About
A small, dependency-free library offering additional enum.StrEnum subclasses and a backport for older Python versions.
Installation
stringenum
is available on PyPI, so you can simply use pip to install it.
pip install stringenum
Usage
-
stringenum.StrEnum
- A backport ofenum.StrEnum
. WhileStrEnum
was added in Python 3.11, version 3.12 brought changes to the__contains__
method inEnumType
, which also impactsStrEnum
.stringenum.StrEnum
includes this__contains__
update from Python 3.12.-
enum.StrEnum
on Python <=3.11>>> 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>>> 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>>> class Color(stringenum.StrEnum): ... RED = "RED" ... GREEN = "GREEN" >>> Color.RED in Color True >>> "RED" in Color True >>> 12 in Color False
-
-
stringenum.CaseInsensitiveStrEnum
- A subclass ofStrEnum
that supports case-insensitive lookup.>>> 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.DuplicateFreeStrEnum
- A subclass ofStrEnum
that ensures all members have unique values and names, raising aValueError
if duplicates are found.>>> 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.DoubleSidedStrEnum
- A subclass ofDuplicateFreeStrEnum
that supports double-sided lookup, allowing both member values and member names to be used for lookups.>>> 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 ofDuplicateFreeStrEnum
that supports case-insenitive double-sided lookup, allowing both member values and member names to be used for lookups.>>> 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 License. See LICENSE for more information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file stringenum-0.3.0.tar.gz
.
File metadata
- Download URL: stringenum-0.3.0.tar.gz
- Upload date:
- Size: 24.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4e379719940f7282eedf641ac0f63809bb34efe9916a1e4044c4b2aff3dd099 |
|
MD5 | 44422b8755cd9fae65f6fdd3d4e61f54 |
|
BLAKE2b-256 | 7f23da9c7ae034a7cdf4c5e73f8520275a81c0bbaa7e1d6ced5f331092e57dc5 |
Provenance
The following attestation bundles were made for stringenum-0.3.0.tar.gz
:
Publisher:
release.yml
on Ravencentric/stringenum
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
stringenum-0.3.0.tar.gz
- Subject digest:
b4e379719940f7282eedf641ac0f63809bb34efe9916a1e4044c4b2aff3dd099
- Sigstore transparency entry: 150641866
- Sigstore integration time:
- Predicate type:
File details
Details for the file stringenum-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: stringenum-0.3.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce70bef67c2124b238a7da4b4ede894d427e08ea8591bf7e9a5a2c79ed42c24e |
|
MD5 | a454f1f1800087281986b211df9968f1 |
|
BLAKE2b-256 | 3e12296ff83c4408306403f7939cd4d31cfa0a3ad490475947f78f08e64d5503 |
Provenance
The following attestation bundles were made for stringenum-0.3.0-py3-none-any.whl
:
Publisher:
release.yml
on Ravencentric/stringenum
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
stringenum-0.3.0-py3-none-any.whl
- Subject digest:
ce70bef67c2124b238a7da4b4ede894d427e08ea8591bf7e9a5a2c79ed42c24e
- Sigstore transparency entry: 150641868
- Sigstore integration time:
- Predicate type: