Enumatic
Enumatic provides string-valued Python enums that automatically assign each member's value from its name.
Project rename:
auto-name-enumis nowenumatic, andAutoNameEnumis nowEnumatic. This is a major release. Installenumaticand change imports tofrom enumatic import Enumatic, auto. Existingfrom auto_name_enum import AutoNameEnumimports remain available through a compatibility package, but new code should useenumaticandEnumatic.
Why Enumatic instead of StrEnum
First of all, back when enumatic was named auto-name-enum and was first released, Python didn't have a StrEnum
type that offered builtin auto() functionality. So, AutoNameEnum (as Enumatic
used to be called) provided the boilerplate to enable auto().
After Python 3.11, the standard library StrEnum provides a lot of the same functionality as Enumatic.
However, there are still some nice things that Enumatic provides beyond StrEnum.
For example, Enumatic preserves the case of your values by defualt, and offers a few helper functions that control how
casing is applied to the values. It also offers the pretty_list() helper which nicely formats the list of values as
well as the rando() method that randomly chooses one of the values. Finally, Enumatic
provides the autodoc() helper to provide context to the values automatically.
Installation
Install the renamed package from PyPI:
pip install enumatic
Specifying your enum
Import Enumatic and its helpers, then define an enum:
from enumatic import Enumatic, auto
class Species(Enumatic):
JAWA = auto()
EWOK = auto()
HUTT = auto()
PYKE = auto()
Getting values
auto() assigns each value from its member name:
>>> print(Species.JAWA.value)
'JAWA'
The enum member also behaves like its string value:
>>> print(Species.JAWA)
'JAWA'
Iterating
Python enums may be iterated over:
for species in Species:
print(f"name: {species.name}, value: {species.value}")
For more information on enums and auto(), see the official Python
documentation.
Mixins
Three mixins 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)
Include a mixin after Enumatic in the class inheritance declaration:
class Species(Enumatic, TitleCaseMixin):
JAWA = auto()
EWOK = auto()
HUTT = auto()
PYKE = auto()
Then, you can check how the values are changed:
>>> print(Species.JAWA)
'Jawa'
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 Species(Enumatic):
JAWA = autodoc("A small, rodent-like species from Tatooine")
EWOK = autodoc("A furry, diminutive species from the forest moon of Endor")
HUTT = autodoc("A large, slug-like species from Nal Hutta")
PYKE = autodoc("A secretive, spice-dealing species from Oba Diah")
autodoc() assigns the value just like auto():
>>> print(Species.JAWA.value)
'JAWA'
Access the description via the .description property:
>>> print(Species.JAWA.description)
'A small, rodent-like species from Tatooine'
A display_name can also be attached as a keyword argument:
class Species(Enumatic):
JAWA = autodoc(description="A small, rodent-like species from Tatooine", display_name="Jawa (Tatooine)")
EWOK = autodoc(description="A furry, diminutive species from the forest moon of Endor", display_name="Ewok (Endor)")
>>> print(Species.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 Species(Enumatic):
JAWA = autodoc("A small, rodent-like species from Tatooine")
EWOK = auto()
HUTT = autodoc("A large, slug-like species from Nal Hutta")
>>> print(Species.JAWA.description)
'A small, rodent-like species from Tatooine'
>>> print(Species.EWOK.description)
None
>>> print(Species.EWOK.display_name)
'EWOK'
Metadata
Release files for enumatic 5.0.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 |
|---|---|---|---|---|
| enumatic-5.0.0.tar.gz | 6.4 kB | Without provenance | Details for enumatic-5.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| enumatic-5.0.0-py3-none-any.whl | Python 3 | none | any | Details for enumatic-5.0.0-py3-none-any.whl |
Total release size: 15.4 kB
Release files / enumatic-5.0.0.tar.gz
| Download URL | enumatic-5.0.0.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
118eaa2b35c6a004e5ec9473a725c39a9e7860d5d95e3fdb0624daf8e8ad6ccd
|
|
BLAKE2b-256 checksum How to use checksums |
9b5205a23a6b4c3e0bc6d4911b65800cc95e120912a0b2a6b9208b5cd0679ea9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","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 / enumatic-5.0.0-py3-none-any.whl
| Download URL | enumatic-5.0.0-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c6e4d8bc5b348b85c9032453c63f2cb50e57364cab433ce0fd36aa9e797a40d4
|
|
BLAKE2b-256 checksum How to use checksums |
b736f3911bcd1c40d4949f04de7f7e947b247610ff1584e0eaf0feb82850c422
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","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 enumatic 5.0.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.