Skip to main content

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


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)

Uploaded Source

Built Distribution

enum_with_dict-0.1.1-py3-none-any.whl (4.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page