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.6+.

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()


print(f"An HTTP method: {HttpMethod.GET}")  # prints "An HTTP method: GET"

There are also case-folding versions available:

>>> from pprint import pprint
>>> from enum import auto
>>> from strenum import StrEnum, LowercaseStrEnum, UppercaseStrEnum
>>>
>>> class Regular(StrEnum):
...     Member = auto()
...
>>>
>>> class Lower(LowercaseStrEnum):
...     Member = auto()
...
>>>
>>> class Upper(UppercaseStrEnum):
...     Member = auto()
...
>>>
>>> pprint((Regular.Member, Lower.Member, Upper.Member))
( <Regular.Member: 'Member'>,
    <Lower.Member: 'member'>,
    <Upper.Member: 'MEMBER'>)

Why not enum34-custom's StrEnum?

Because it's not compatible with modern versions of python (see issue).

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 are run automatically as part of the test suite.

Running the tests

Tests can be run using make:

make test

This will create a virutal environment, install the module and its test dependencies and run the tests. Alternatively you can do the same thing manually:

python3 -m venv .venv
.venv/bin/pip install .[test]
.venv/bin/pytest

License

MIT

N.B. Starting with Python 3.10, enum.StrEnum is available in the standard library. This implementation is not a drop-in replacement for the standard library implementation. Sepcifically, 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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

StrEnum-0.4.4.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

StrEnum-0.4.4-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file StrEnum-0.4.4.tar.gz.

File metadata

  • Download URL: StrEnum-0.4.4.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.1 CPython/3.8.6

File hashes

Hashes for StrEnum-0.4.4.tar.gz
Algorithm Hash digest
SHA256 fb7fad837451e362307d6a9de5b3a6c47bc14d006db79763634def7260c16aee
MD5 560b0dd548e9d4d96146fc2e3294f518
BLAKE2b-256 c1f1bcdf30dd4051c2c0900285a23a489fdfb081b96cae4abd07bfd68562c81f

See more details on using hashes here.

File details

Details for the file StrEnum-0.4.4-py3-none-any.whl.

File metadata

  • Download URL: StrEnum-0.4.4-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.1 CPython/3.8.6

File hashes

Hashes for StrEnum-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 20f404b2da9d37c5772370e69dbbd9d78ace580a0c57d7813c30677fb286e4d1
MD5 1248cd324ee32b7cdc04139226a693a3
BLAKE2b-256 5addf6c4d781b309dd348618e9d4767d3853cc6791fd79a0ae2e1a6849dc6b7c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page