skillfed

backports.strenum

Base class for creating enumerated constants that are also subclasses of str

backports-strenum v1.3.1 8.4M downloads/30d#1,626 on PyPI8
Permissive license MIT DORMANT released

What it is and what it does

backports.strenum is a direct copy of Python 3.11's StrEnum class, ported to run on Python 3.8.6 through 3.10. It lets you create enumeration classes whose members are both enum constants and string values, so they can be used interchangeably with strings in most contexts. Members support string operations like upper() and lower(), and equality checks work naturally (e.g., Color.RED == "red" returns True).

The package is designed as a conditional dependency: code should import from the standard library on Python 3.11+, and fall back to backports.strenum only on earlier versions. It has no runtime dependencies and installs cleanly. Maintenance is dormant but intentional—the package is a static backport unlikely to need updates unless Python's enum semantics shift significantly.

Use it for:

  • Define string-based enums in libraries that must support Python 3.8–3.10 while using native StrEnum on 3.11+.
  • Replace hardcoded string constants with type-safe enum members that retain string compatibility.
  • Build configuration or status classes where members need to serialize as strings and be usable in string comparisons.
  • Migrate legacy code from plain string constants to enums without breaking string-based APIs.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides StrEnum, a string-based enumeration class from Python 3.11, for use on Python 3.8.6 through 3.10, allowing enum members to behave as both strings and enumeration constants.

Yes, if you need StrEnum on Python 3.8–3.10 and can configure it as a conditional dependency (install only on <3.11). The package is minimal, has no external dependencies, carries no known vulnerabilities, and uses a permissive MIT license. Dormant maintenance is acceptable because it is a static backport of a standard library feature. Not worth installing on Python 3.11+, where the standard library StrEnum should be used directly.

Install

backports-strenum on PyPI

pip

pip install backports-strenum

uv

uv add backports-strenum

poetry

poetry add backports-strenum

Installing backports.strenum

Before you install

Low install friction with no runtime dependencies. Maintenance is dormant—last release was 2023-12-09 and the repository shows no recent activity—but the package is intentionally minimal and unlikely to require updates unless Python's enum behavior changes.

License in practice

MIT license permits unrestricted use, modification, and distribution with minimal restrictions, making it safe to include in any project type.

Quickstart

pip install backports.strenum

from backports.strenum import StrEnum

class Color(StrEnum):
    RED = "red"
    BLUE = "blue"

print(Color.RED == "red")  # True

Package only installs on Python >=3.8.6 and <3.11; on Python 3.11+ the standard library StrEnum should be used instead.

Verify before relying

  • Whether the package's behavior fully matches Python 3.11's StrEnum in all edge cases, particularly around container operations that change in Python 3.12.
  • Whether conditional dependency configuration is documented for common package managers.
  • Full compatibility with all string operations and edge cases described in Python 3.11 enum documentation.

Package facts

License MIT (permissive)
Python support capped below the current Python release (>=3.8.6,<3.11)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance dormant — 979 days since the last release
Last repo commit
First released
Downloads 8,402,027/month — #1,626 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: backports_strenum-1.3.1-py3-none-any.whl

Keywords: backports, enum, strenum

Development Status :: 3 - AlphaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.9

Tags

string enum backportstrenum python 3.8enum string subclassbackport python 3.11 enumconditional enum dependencystring enumeration class
backportenumconditional-dependency

More Software Development packages