Skip to main content

An Enum that inherits from str.

Project description

StrEnum

Build Status

N.B. From python 3.10, enum.StrEnum is part of the standard library. An identical implementation is available on PyPI for 3.8+ at backports.strenum. The below implementation is not necessarily compatible with either.

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"

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

Project details


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.3.tar.gz (19.3 kB view hashes)

Uploaded Source

Built Distribution

StrEnum-0.4.3-py3-none-any.whl (4.3 kB view hashes)

Uploaded Python 3

Supported by

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