Enum with to_dict method.
Project description
EnumWithDict
EnumWithDict
is a Python package that extends the standard library's Enum
class to include to_dict
and get_initial
class methods. This enhancement allows for straightforward conversion of enum classes to dictionaries and provides easy access to the initial enum value, facilitating a more versatile use of enumerations in Python applications.
Features
- to_dict: Convert an enum class to a dictionary representation, mapping member names to their values.
- get_initial: Retrieve the first value defined in the enum, useful for cases where a default or initial value is needed.
Installation
Install EnumWithDict
using pip:
pip install enum_with_dict
Usage
Defining an Enum with EnumWithDict
from enum_with_dict import EnumWithDict
class Color(EnumWithDict):
RED = 'red'
GREEN = 'green'
BLUE = 'blue'
Converting an Enum to a Dictionary
color_dict = Color.to_dict()
print(color_dict)
# Output: {'RED': 'red', 'GREEN': 'green', 'BLUE': 'blue'}
Getting the Initial Enum Value
initial_color = Color.get_initial()
print(initial_color)
# Output: 'red'
LICENSE
EnumWithDict
is released under the MIT License. See the LICENSE file for more details.
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
enum_with_dict-0.1.1.tar.gz
(3.5 kB
view hashes)
Built Distribution
Close
Hashes for enum_with_dict-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9506d88a628787d5aeead27e0c4f5a81e777410cc55a43ca7387898bf6d38da5 |
|
MD5 | 57a39ebaa5b00b774e42cb17acc8bcab |
|
BLAKE2b-256 | ab7c317d6eb4dcc84d67d14a2bcf6f3619b414fcc18e57d49bbd52e79e7635cf |