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. WhileStrEnumwas added in Python 3.11, version 3.12 brought changes to the__contains__method inEnumType, which also impactsStrEnum.stringenum.StrEnumincludes this__contains__update from Python 3.12.-
enum.StrEnumon 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.StrEnumon 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.StrEnumon 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.DuplicateFreeStrEnum- A subclass ofStrEnumthat ensures all members have unique values and names, raising aValueErrorif 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.CaseInsensitiveStrEnum- A subclass ofDuplicateFreeStrEnumthat 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.DoubleSidedStrEnum- A subclass ofDuplicateFreeStrEnumthat 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 ofDuplicateFreeStrEnumthat 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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stringenum-0.6.0.tar.gz.
File metadata
- Download URL: stringenum-0.6.0.tar.gz
- Upload date:
- Size: 26.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b47213f239487ec8051e9cc54d68b4955509808e33126c6cc4ab53e47f66d01
|
|
| MD5 |
ca95fc0b886568a33f99b5b0404c38b2
|
|
| BLAKE2b-256 |
e4bfe8069c06e43869d9371022a8805fe497ff80b50e5b45b91b3a795b669ca3
|
Provenance
The following attestation bundles were made for stringenum-0.6.0.tar.gz:
Publisher:
release.yml on Ravencentric/stringenum
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stringenum-0.6.0.tar.gz -
Subject digest:
2b47213f239487ec8051e9cc54d68b4955509808e33126c6cc4ab53e47f66d01 - Sigstore transparency entry: 157566984
- Sigstore integration time:
-
Permalink:
Ravencentric/stringenum@b47d003eaaa0b1d483398f2c46a182183cc3f2e2 -
Branch / Tag:
refs/tags/v0.6.0 - Owner: https://github.com/Ravencentric
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b47d003eaaa0b1d483398f2c46a182183cc3f2e2 -
Trigger Event:
push
-
Statement type:
File details
Details for the file stringenum-0.6.0-py3-none-any.whl.
File metadata
- Download URL: stringenum-0.6.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e132edae8bb2bf5c37cae55f5d4ec51c7596e5064fe2d3e6bd567e0ca773063d
|
|
| MD5 |
82ff51f4e53ff9d7dcc2fbe3b692a0b9
|
|
| BLAKE2b-256 |
70a6d21747d479369d30df2f5d1a86f9f426b7839c4e8a5fb32d5bff24c0f9a5
|
Provenance
The following attestation bundles were made for stringenum-0.6.0-py3-none-any.whl:
Publisher:
release.yml on Ravencentric/stringenum
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stringenum-0.6.0-py3-none-any.whl -
Subject digest:
e132edae8bb2bf5c37cae55f5d4ec51c7596e5064fe2d3e6bd567e0ca773063d - Sigstore transparency entry: 157566985
- Sigstore integration time:
-
Permalink:
Ravencentric/stringenum@b47d003eaaa0b1d483398f2c46a182183cc3f2e2 -
Branch / Tag:
refs/tags/v0.6.0 - Owner: https://github.com/Ravencentric
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@b47d003eaaa0b1d483398f2c46a182183cc3f2e2 -
Trigger Event:
push
-
Statement type: