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 Aliens(AutoNameEnum):
JAWA = auto()
EWOK = auto()
HUTT = auto()
PYKE = auto()
Getting values
Using the class, verify the value of JAWA would be 'JAWA':
>>> print(Aliens.JAWA.value)
'JAWA'
You may also get the same value by just using the name of the item:
>>> print(Aliens.JAWA)
'JAWA'
Iterating
Python enums may be iterated over:
for alien in Aliens:
print(f"name: {alien.name}, value: {alien.value}")
For more information on enums (and the auto method), see [the official docs] (https://docs.python.org/3/library/enum.html)
Mixins
There are two mixins provided that change the case of member values for both auto() and autodoc():
LowerCaseMixin: values are in all lower-caseTitleCaseMixin: values are in title-case (lower-case except for first letter)KebabCaseMixin: values are in kebab-case (dashes instead of underscores)
When these mixins are used, they must be included after AutoNameEnum in the class inheritance declaration:
class Aliens(AutoNameEnum, TitleCaseMixin)
JAWA = auto()
EWOK = auto()
HUTT = auto()
PYKE = auto()
Documented members with autodoc()
The autodoc() function works like auto(), but also attaches a description and/or
display_name to each enum member. This is useful for self-documenting enums where members
need human-readable explanations or labels:
class Aliens(AutoNameEnum):
JAWA = autodoc("A small, rodent-like alien from Tatooine")
EWOK = autodoc("A furry, diminutive alien from the forest moon of Endor")
HUTT = autodoc("A large, slug-like alien from Nal Hutta")
PYKE = autodoc("A secretive, spice-dealing alien from Oba Diah")
The value works just like auto():
>>> print(Aliens.JAWA.value)
'JAWA'
Access the description via the .description property:
>>> print(Aliens.JAWA.description)
'A small, rodent-like alien from Tatooine'
A display_name can also be attached as a keyword argument:
class Aliens(AutoNameEnum):
JAWA = autodoc(description="A small, rodent-like alien from Tatooine", display_name="Jawa (Tatooine)")
EWOK = autodoc(description="A furry, diminutive alien from the forest moon of Endor", display_name="Ewok (Endor)")
>>> print(Aliens.JAWA.display_name)
'Jawa (Tatooine)'
You can mix auto() and autodoc() in the same enum. Members created with auto() will return
None for .description and their value for .display_name:
class Aliens(AutoNameEnum):
JAWA = autodoc("A small, rodent-like alien from Tatooine")
EWOK = auto()
HUTT = autodoc("A large, slug-like alien from Nal Hutta")
>>> print(Aliens.JAWA.description)
'A small, rodent-like alien from Tatooine'
>>> print(Aliens.EWOK.description)
None
>>> print(Aliens.EWOK.display_name)
'EWOK'
Metadata
Release files for auto-name-enum 4.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| auto_name_enum-4.2.0.tar.gz | 5.4 kB | Without provenance | Details for auto_name_enum-4.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| auto_name_enum-4.2.0-py3-none-any.whl | Python 3 | none | any | Details for auto_name_enum-4.2.0-py3-none-any.whl |
Total release size: 12.4 kB
Release files / auto_name_enum-4.2.0.tar.gz
| Download URL | auto_name_enum-4.2.0.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6b8bc1a9b813c5bcf7cf3fce7ad6a2ab16eafa3265e06dc2178f5a76b8925d21
|
|
BLAKE2b-256 checksum How to use checksums |
6aeacf2a8472b0010d56ad76bd4be8b3d8054bf396f1928b9cfc4efc23f2edc8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / auto_name_enum-4.2.0-py3-none-any.whl
| Download URL | auto_name_enum-4.2.0-py3-none-any.whl |
|---|---|
| Size | 7.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
262dec8891ff4fbb648ee845c1b39b2e41f48dc97ff4b74b0cac22c42d3a0c1e
|
|
BLAKE2b-256 checksum How to use checksums |
8968858413671641a6da5fc7a98d611c3dc54f355ab6de688baeab500dd29fef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for auto-name-enum 4.2.0
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.