Skip to main content

EnhancedEnum

EnhancedEnum is a generic, enhanced enumeration class that extends the functionality of Python’s standard Enum class. It provides additional convenience methods for a more user-friendly approach to handling enumerations. This class utilizes Python’s generics to ensure type safety and clarity.

Features

  • User-Friendly String Representation: Override the __str__ method to return the name of the enum member.

  • Listing Members: Easily list all members of the enumeration.

  • Validation: Check if a given value is part of the enumeration.

  • Tuple Conversion: Convert enum members into a tuple.

  • Navigation: Navigate to the next or previous enum members in sequence.

  • Creation from String: Instantiate an enum member from its string name.

  • Creation from Value: Instantiate an enum member from its value.

Installation

You can copy the EnhancedEnum class code into your project, or import it if you’ve saved it as a separate Python file.

Usage

Below is an example of how you might define and use the EnhancedEnum:

from enum import Enum, auto
from enhanced_enum import EnhancedEnum

class Color(EnhancedEnum):
    RED = auto()
    GREEN = auto()
    BLUE = auto()

# List all members
print(Color.list_all())

# Validate a member
print(Color.validate(Color.RED))

# Get next and previous members
print(Color.RED.next())
print(Color.RED.previous())

# Create a member from a string
print(Color.from_string('RED'))

# Create a member from a value
print(Color.from_value(1))

Methods

  • __str__: Return a more user-friendly string representation of the enum member.

  • list_all: Return a list of all enum members.

  • validate: Check if a given value is a valid member of the enum.

  • as_tuple: Return the enum members as a tuple.

  • next: Return the next enum member in sequence.

  • previous: Return the previous enum member in sequence.

  • from_string: Return the corresponding enum member for a given name.

  • from_value: Return the corresponding enum member for a given numeric value.

Contributing

Contributions, issues, and feature requests are welcome. Feel free to check issues page if you want to contribute.

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Massimo Ghiani - m.ghiani@gmail.com

Project Link: https://github.com/m-ghiani/ENHANCED_ENUMS

Metadata

Release files for enhanced-enums 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for enhanced-enums 1.0.2
File Size Uploaded Provenance
enhanced-enums-1.0.2.tar.gz 5.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for enhanced-enums 1.0.2
File Interpreter ABI Platform
enhanced_enums-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.6 kB

Release files / enhanced-enums-1.0.2.tar.gz

Download URL enhanced-enums-1.0.2.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8ce258ae05a08676ebdb421646b5229a05a3b3006af335e2126044f77e7889b6
BLAKE2b-256 checksum
How to use checksums
7653889192b23721661a26f0e4bb6124dcd12f4bd448b8ad6a8f80b6ce151d15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Release files / enhanced_enums-1.0.2-py3-none-any.whl

Download URL enhanced_enums-1.0.2-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
708947bf03a255c9eac937337d35044bec143308f9ce1aa7b86b8c518b0586ea
BLAKE2b-256 checksum
How to use checksums
bdfe5102ea66e714d817a0b6da88c6cf3ba1f023c10a28bbdd95e5c6943fb4a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.6

Security for enhanced-enums 1.0.2

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.

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page