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.2.0.tar.gz
(3.7 kB
view hashes)
Built Distribution
Close
Hashes for enum_with_dict-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88022601cbb6d4f891134d14b45960ebd8645b6ef145ddcb03815405e26e9b5a |
|
MD5 | 497516d230e795b80859555f9681f528 |
|
BLAKE2b-256 | 0e2dbaffab18b598b81606be064c30217f4a3624185c9e3cda06fc45a13c5b4d |