Skip to main content

String-based Enum class that automatically assigns values

Project description

A utility for producing enums with automatic names

This package provides an extension of python Enum objects that automatically assigns values to members. This uses the auto() feature to assign text values to the enums instead of having to manually set them.

Specifying your enum

For example, you might create an enum with this like so:

class Pets(AutoNameEnum):
    DOG = auto()
    CAT = auto()
    PIG = auto()

Getting values

Using the class, verify the value of DOG would be 'dog':

>>> print(Pets.DOG.value)
'DOG'

You may also get the same value by just using the name of the item:

>>> print(Pets.DOG)
'DOG'

Iterating

Python enums may be iterated over:

for pet in Pets:
    print(f"name: {pet.name}, value: {pet.value}")

For more information on enums (and the auto method), see [the official docs] (https://docs.python.org/3/library/enum.html)

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

auto-name-enum-2.0.0.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

auto_name_enum-2.0.0-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file auto-name-enum-2.0.0.tar.gz.

File metadata

  • Download URL: auto-name-enum-2.0.0.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.10 Linux/5.4.72-microsoft-standard-WSL2

File hashes

Hashes for auto-name-enum-2.0.0.tar.gz
Algorithm Hash digest
SHA256 aa38d9c2730b95b0bb700cd93fb5f65a2a982f6d79bbbcd0c64e5bcfe8f3d5b1
MD5 75eb64e27a78b45a2b182ec104dfd56e
BLAKE2b-256 4d2f505ed1c1ab1dbb8c14501b297e1f830aa1c36ce66d2d5a47320b6e04ff95

See more details on using hashes here.

File details

Details for the file auto_name_enum-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: auto_name_enum-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.10 Linux/5.4.72-microsoft-standard-WSL2

File hashes

Hashes for auto_name_enum-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb9fe25985d7ef890e7b419d242b9ec145162ae1252121f8a5e3e8cca0e6d87a
MD5 2860fa41f1cef00393ea688d9d66aeed
BLAKE2b-256 41886a03f04851af6ada6e0a2169d78fc9e85cbd189e81f7e80523ccd2261bcb

See more details on using hashes here.

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