Install & Compatibility
Where this runs
tested against v0.4.15 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.010s · 17.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.6s · import 0.010s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
StrEnum
✓ from strenum import StrEnum
LowercaseStrEnum
✓ from strenum import LowercaseStrEnum
CamelCaseStrEnum
✓ from strenum import CamelCaseStrEnum
auto
✓ from enum import auto
The 'auto' function is part of Python's standard 'enum' module, not 'strenum'.
This quickstart demonstrates defining a basic `StrEnum` where `auto()` uses the member name directly, and a `LowercaseStrEnum` which converts `auto()` values to lowercase. It also shows manual string assignment and how `StrEnum` members behave like strings, including comparison.
from enum import auto
from strenum import StrEnum, LowercaseStrEnum
class HttpMethod(StrEnum):
GET = auto() # Value will be 'GET'
POST = 'post_value' # Explicitly assigned string value
PUT = auto()
class FileExtension(LowercaseStrEnum):
TXT = auto() # Value will be 'txt'
PDF = auto()
assert HttpMethod.GET == 'GET'
assert HttpMethod.POST == 'post_value'
assert HttpMethod.PUT == 'PUT'
assert FileExtension.TXT == 'txt'
assert FileExtension.PDF == 'pdf'
print(f"HTTP Method: {HttpMethod.GET}")
print(f"File Type: {FileExtension.PDF}")
# Enums compare equal to their string value
assert HttpMethod.GET == "GET"
# However, it's generally recommended to compare enum to enum for type safety
if HttpMethod.GET is HttpMethod.GET:
print("GET method detected.")
Debug
Known issues
breakingSupport for Python 3.6 was dropped in version 0.4.9. Users on older Python versions will need to pin `strenum<0.4.9` or upgrade their Python environment.fixUpgrade Python to 3.7+ or pin `strenum` to a version less than 0.4.9 (`pip install "strenum<0.4.9"`).
affects: >=0.4.9
gotchaPython 3.11 introduced `enum.StrEnum` in the standard library. The `strenum` library is *not* a drop-in replacement for the standard library's `StrEnum`, especially regarding the default behavior of `auto()`. The `strenum.StrEnum` preserves the member name as its value when `auto()` is used (e.g., `MY_VALUE` becomes `'MY_VALUE'`), while the standard library's `enum.StrEnum` defaults to lowercasing (`MY_VALUE` becomes `'my_value'`).fixBe explicit when using `auto()`: use `strenum.StrEnum` for literal name values, or `strenum.LowercaseStrEnum`, `strenum.CamelCaseStrEnum`, etc., for specific casing. If migrating to `enum.StrEnum` (stdlib), be aware of its default lowercasing behavior for `auto()` or define a custom `_generate_next_value_`.
affects: All versions, when considering migration to Python 3.11+ stdlib `StrEnum`
gotchaWhen using the case-converting `StrEnum` subclasses (e.g., `CamelCaseStrEnum`, `KebabCaseStrEnum`), the automatic name conversion to value only applies when `auto()` is used. Manually assigned values will be used exactly as provided, without any case transformation.fixAlways use `auto()` if you expect the name conversion to apply to the member's value, or explicitly assign the desired string value if it should not be converted.
affects: All versions with case-converting StrEnum subclasses
gotchaWhile `strenum` members compare equal to their underlying string values (e.g., `MyEnum.FOO == "FOO"` returns `True`), relying on this for critical logic can sometimes lead to subtle bugs or typos. It's generally safer and more type-explicit to compare enum members directly (e.g., `MyEnum.FOO is MyEnum.FOO` or `MyEnum.FOO == another_enum_member`).fixPrefer comparing enum members to other enum members. If comparing to a string is necessary, consider its implications for type safety and potential errors.
affects: All versions
gotchaIn some parts of the Python standard library, checks for `type(unknown) == str` are performed instead of `isinstance(unknown, str)`. In these specific cases, a `strenum` member might not be recognized as a plain string. To ensure compatibility, you might need to explicitly cast the enum member to `str` (e.g., `str(MyStrEnum.MY_MEMBER)`).fixIf encountering unexpected type mismatches in string-sensitive standard library functions, explicitly cast the `strenum` member to `str`.
affects: All versions
Upgrade
Version history
0.4.15latest on PyPI · released Jun 29, 2023
Audit
Dependencies
No dependency data recorded yet.