philiprehberger-enum-tools
Practical utilities for Python enums — lookup, validation, listing, and serialization.
Installation
pip install philiprehberger-enum-tools
Usage
from enum import Enum, auto
from philiprehberger_enum_tools import lookup, choices, values, names, validate
class Color(Enum):
RED = "red"
GREEN = "green"
BLUE = "blue"
Safe Lookup
lookup(Color, "red") # Color.RED
lookup(Color, "yellow") # None
lookup(Color, "yellow", default=Color.RED) # Color.RED
Validation
validate(Color, "red") # Color.RED
validate(Color, "yellow") # ValueError: 'yellow' is not a valid Color value. Valid values: 'red', 'green', 'blue'
Listing
values(Color) # ['red', 'green', 'blue']
names(Color) # ['RED', 'GREEN', 'BLUE']
choices(Color) # [('red', 'RED'), ('green', 'GREEN'), ('blue', 'BLUE')]
AutoEnum
Enum subclass where auto() generates lowercase member names as values.
from philiprehberger_enum_tools import AutoEnum
from enum import auto
class Status(AutoEnum):
ACTIVE = auto()
INACTIVE = auto()
PENDING = auto()
Status.ACTIVE.value # 'active'
Status.PENDING.value # 'pending'
SerializableEnum
Enum that serializes to its value in JSON.
import json
from philiprehberger_enum_tools import SerializableEnum, SerializableEncoder
class Priority(SerializableEnum):
LOW = 1
MEDIUM = 2
HIGH = 3
json.dumps({"priority": Priority.HIGH}, cls=SerializableEncoder)
# '{"priority": 3}'
API
| Function / Class | Description |
|---|---|
lookup(enum_class, value, *, default=None) |
Safe value-to-member lookup, returns default if not found |
choices(enum_class) |
List of (value, name) tuples for forms and CLIs |
values(enum_class) |
List of all member values |
names(enum_class) |
List of all member names |
validate(enum_class, value) |
Lookup or raise ValueError with valid options |
AutoEnum |
Enum subclass where auto() generates lowercase name as value |
SerializableEnum |
Enum that serializes to its value via SerializableEncoder |
SerializableEncoder |
JSON encoder supporting SerializableEnum members |
Development
pip install -e .
python -m pytest tests/ -v
Support
If you find this project useful:
License
Metadata
Release files for philiprehberger-enum-tools 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| philiprehberger_enum_tools-0.1.7.tar.gz | 5.1 kB | Without provenance | Details for philiprehberger_enum_tools-0.1.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| philiprehberger_enum_tools-0.1.7-py3-none-any.whl | Python 3 | none | any | Details for philiprehberger_enum_tools-0.1.7-py3-none-any.whl |
Total release size: 9.7 kB
Release files / philiprehberger_enum_tools-0.1.7.tar.gz
| Download URL | philiprehberger_enum_tools-0.1.7.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
523e64948b5cdad10960d9475cc095c17e9b0ab063e7b4f433704912efd2d9bd
|
|
BLAKE2b-256 checksum How to use checksums |
a59b0301b018a07b38e40878c01a8e79ffbb69c4717349f5b26c106d5018b1c2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Release files / philiprehberger_enum_tools-0.1.7-py3-none-any.whl
| Download URL | philiprehberger_enum_tools-0.1.7-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a2919d20cbe72b30d401eb88e921d12fa3ca129561af16b55397f776f991845b
|
|
BLAKE2b-256 checksum How to use checksums |
1d91515f04a4b11987f0b51e9aee4018ff9610b8baa2c0dc5f1789c30a416c01
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.13
|
Security for philiprehberger-enum-tools 0.1.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.