Skip to main content

StrEnum

Build Status

StrEnum is a Python enum.Enum that inherits from str to complement enum.IntEnum in the standard library. Supports python 3.7+.

Installation

You can use pip to install.

pip install StrEnum

Usage

from enum import auto
from strenum import StrEnum


class HttpMethod(StrEnum):
    GET = auto()
    HEAD = auto()
    POST = auto()
    PUT = auto()
    DELETE = auto()
    CONNECT = auto()
    OPTIONS = auto()
    TRACE = auto()
    PATCH = auto()


assert HttpMethod.GET == "GET"

# You can use StrEnum values just like strings:

import urllib.request

req = urllib.request.Request('https://www.python.org/', method=HttpMethod.HEAD)
with urllib.request.urlopen(req) as response:
    html = response.read()

assert len(html) == 0  # HEAD requests do not (usually) include a body

There are classes whose auto() value folds each member name to upper or lower case:

from enum import auto
from strenum import LowercaseStrEnum, UppercaseStrEnum


class Tag(LowercaseStrEnum):
    Head = auto()
    Body = auto()
    Div = auto()


assert Tag.Head == "head"
assert Tag.Body == "body"
assert Tag.Div == "div"


class HttpMethod(UppercaseStrEnum):
    Get = auto()
    Head = auto()
    Post = auto()


assert HttpMethod.Get == "GET"
assert HttpMethod.Head == "HEAD"
assert HttpMethod.Post == "POST"

As well as classes whose auto() value converts each member name to camelCase, PascalCase, kebab-case, snake_case and MACRO_CASE:

from enum import auto
from strenum import CamelCaseStrEnum, PascalCaseStrEnum
from strenum import KebabCaseStrEnum, SnakeCaseStrEnum
from strenum import MacroCaseStrEnum


class CamelTestEnum(CamelCaseStrEnum):
    OneTwoThree = auto()


class PascalTestEnum(PascalCaseStrEnum):
    OneTwoThree = auto()


class KebabTestEnum(KebabCaseStrEnum):
    OneTwoThree = auto()


class SnakeTestEnum(SnakeCaseStrEnum):
    OneTwoThree = auto()


class MacroTestEnum(MacroCaseStrEnum):
    OneTwoThree = auto()


assert CamelTestEnum.OneTwoThree == "oneTwoThree"
assert PascalTestEnum.OneTwoThree == "OneTwoThree"
assert KebabTestEnum.OneTwoThree == "one-two-three"
assert SnakeTestEnum.OneTwoThree == "one_two_three"
assert MacroTestEnum.OneTwoThree == "ONE_TWO_THREE"

As with any Enum you can, of course, manually assign values.

from strenum import StrEnum


class Shape(StrEnum):
    CIRCLE = "Circle"


assert Shape.CIRCLE == "Circle"

Doing this with the case-changing classes, though, won't manipulate values--whatever you assign is the value they end up with.

from strenum import KebabCaseStrEnum


class Shape(KebabCaseStrEnum):
    CIRCLE = "Circle"


# This will raise an AssertionError because the value wasn't converted to kebab-case.
assert Shape.CIRCLE == "circle"

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please ensure tests pass before submitting a PR. This repository uses Black and Pylint for consistency. Both can be run with make lint.

Running the tests

This project is managed with uv. Tests can be run using make:

make test

This will create a virtual environment, install the module and its development dependencies and run the tests. Alternatively you can do the same thing directly with uv:

uv run pytest
uv run black --check .
uv run pylint src/strenum/*.py tests/*.py

Releasing

Releases are published to PyPI by the Release GitHub workflow. The version comes from the git tag, so there is nothing to edit before releasing:

git tag -a v0.4.16 -m "Release 0.4.16"
git push origin v0.4.16

The workflow runs the tests and linters, builds the sdist and wheel, checks that their version matches the tag, and then waits for approval in the pypi environment before uploading to PyPI using trusted publishing.

License

MIT

N.B. Starting with Python 3.11, enum.StrEnum is available in the standard library. This implementation is not a drop-in replacement for the standard library implementation. Specifically, the Python devs have decided to case fold name to lowercase by default when auto() is used which I think violates the principle of least surprise.

Metadata

Release files for StrEnum 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for StrEnum 0.5.0
File Size Uploaded Provenance Actions
strenum-0.5.0.tar.gz 148.2 kB With provenance Details for strenum-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for StrEnum 0.5.0
File Interpreter ABI Platform Actions
strenum-0.5.0-py3-none-any.whl Python 3 none any Details for strenum-0.5.0-py3-none-any.whl

Total release size: 157.3 kB

Release files / strenum-0.5.0.tar.gz

Download URL strenum-0.5.0.tar.gz
Size 148.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9c50a5ce647c0a625ac25c1b719039e745466b6a04bd001aee6376381d8cdce7
BLAKE2b-256 checksum
How to use checksums
80c608eb36e25f318037c93ae16f75e515e95ebf2801e42428d10b7ff332f9dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Release files / strenum-0.5.0-py3-none-any.whl

Download URL strenum-0.5.0-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f23a35daa03c948885d616463f75ebb0f179cb13acd17c3ac3b2394bfc343967
BLAKE2b-256 checksum
How to use checksums
0494598975013306c83df1820bf6cf7424da43c98eff190d528b733be615e8c6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Security for StrEnum 0.5.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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for strenum-0.5.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page