CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-aenum

Advanced Enumerations (compatible with Python's stdlib Enum), NamedTuples, and NamedConstants

76

1.20x
Overview
Eval results
Files

aenum

Advanced Enumerations (compatible with Python's stdlib Enum), NamedTuples, and NamedConstants. This library provides enhanced enumeration capabilities that extend Python's standard library functionality with features like multiple values, auto-numbering, bitwise operations, and unique constraints.

Package Information

  • Package Name: aenum
  • Language: Python
  • Installation: pip install aenum
  • Python Support: 2.7, 3.3-3.13

Core Imports

from aenum import Enum, IntEnum, StrEnum, Flag, IntFlag

Basic imports for most use cases:

from aenum import Enum, auto, unique

Basic Usage

from aenum import Enum, IntEnum, StrEnum, auto

# Basic enumeration
class Color(Enum):
    RED = 1
    GREEN = 2
    BLUE = 3

# String enumeration (useful for APIs)
class Status(StrEnum):
    PENDING = 'pending'
    PROCESSING = 'processing'
    COMPLETE = 'complete'

# Integer enumeration (sortable, comparable)
class Priority(IntEnum):
    LOW = 1
    MEDIUM = 2
    HIGH = 3

# Using auto for automatic value assignment
class Direction(Enum):
    NORTH = auto()
    SOUTH = auto()
    EAST = auto()
    WEST = auto()

# Usage examples
print(Color.RED)  # Color.RED
print(Status.PENDING)  # 'pending'
print(Priority.HIGH > Priority.LOW)  # True
print(Direction.NORTH.value)  # 1

# Functional API for simple cases
Animal = Enum('Animal', 'ANT BEE CAT DOG')
print(Animal.CAT)  # Animal.CAT

Architecture

The aenum library is organized around these key components:

  • Core Enum Classes: Enum, IntEnum, StrEnum provide the foundation with stdlib compatibility
  • Flag Classes: Flag, IntFlag enable bitwise combinable enumerations
  • Specialized Enums: Auto-numbering, ordering, uniqueness, and multi-value enums
  • NamedTuple: Enhanced tuple implementation with named fields and default values
  • NamedConstant: Immutable constant containers for configuration and settings
  • Utilities: Functions for extending, converting, and manipulating enumerations

Capabilities

Core Enumerations

Basic enumeration classes that provide the foundation for creating typed constants with optional integer or string behavior.

class Enum:
    def __init__(self, value): ...

class IntEnum(int, Enum):
    def __init__(self, value): ...

class StrEnum(str, Enum):
    def __init__(self, value): ...

class ReprEnum(Enum):
    def __repr__(self): ...

Core Enumerations

Flags and Bitwise Operations

Flag enumerations that support bitwise operations for combining multiple values, commonly used for permissions, feature toggles, and configuration options.

class Flag(Enum):
    def __or__(self, other): ...
    def __and__(self, other): ...
    def __xor__(self, other): ...
    def __invert__(self): ...

class IntFlag(int, Flag):
    def __init__(self, value): ...

class FlagBoundary(Enum):
    STRICT: ...
    CONFORM: ...
    EJECT: ...
    KEEP: ...

Flags and Bitwise Operations

Advanced Enum Features

Specialized enumeration classes that provide automatic numbering, ordering, uniqueness constraints, and multi-value support for complex enumeration needs.

class AutoNumberEnum(Enum):
    def _generate_next_value_(name, start, count, last_values): ...

class AutoEnum(Enum):
    """Auto-enum that uses _generate_next_value_ for missing values (Python 3 only)."""

class OrderedEnum(Enum):
    def __lt__(self, other): ...
    def __le__(self, other): ...
    def __gt__(self, other): ...
    def __ge__(self, other): ...

class UniqueEnum(Enum): ...

class MultiValueEnum(Enum): ...

class AddValueEnum(Enum):
    def _generate_next_value_(name, start, count, last_values): ...

Advanced Enum Features

NamedTuple

Enhanced tuple implementation with named fields, default values, docstrings, and methods for creating structured data containers.

def NamedTuple(typename, fields, **kwargs):
    """
    Create a new NamedTuple class.
    
    Args:
        typename (str): Name of the new class
        fields (str | list): Field names as string or list
        **kwargs: Additional options
    
    Returns:
        type: New NamedTuple class
    """

class TupleSize(Enum):
    fixed: ...
    minimum: ...
    variable: ...

NamedTuple

Utilities and Advanced Features

Helper functions, decorators, and classes for working with enumerations including uniqueness validation, runtime extension, conversion utilities, and named constants.

def unique(enumeration):
    """Decorator to ensure enum members have unique values."""

def extend_enum(enumeration, name, *args, **kwds):
    """Add new members to an existing enumeration."""

def export(enum_class, namespace=None):
    """Export enum members to a namespace."""

class auto:
    """Placeholder class for automatic value assignment."""

class NamedConstant:
    """Base class for named constants."""

class constant:
    """Descriptor for constant values."""

Utilities and Advanced Features

Types

# Core type definitions used across the API
EnumMeta = EnumType  # Metaclass for Enum classes

class _EnumArgSpec:
    args: list
    varargs: str
    varkw: str
    defaults: tuple

# Sentinel values
class _auto_null: ...
class no_arg: ...
undefined: object

# Helper types for advanced features
class Member: ...
class NonMember: ...
class skip: ...
nonmember = skip

# Property types
class enum_property(property): ...

Install with Tessl CLI

npx tessl i tessl/pypi-aenum
Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/aenum@3.1.x