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

Uploaded Source

Built Distribution

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

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: StrEnum-0.4.3.tar.gz
  • Upload date:
  • Size: 19.3 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.3.tar.gz
Algorithm Hash digest
SHA256 e9eaf9febdb7a754bff9906db92dd3528f5426be9d0813903efd1dfcb8b5aa3b
MD5 7340b7ef3202d1cb8d9899a23fc6b569
BLAKE2b-256 199c41cbe0f2ab410118ebde7ed690a1b3b9a25377d0f901653fa8d3c59929ef

See more details on using hashes here.

File details

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

File metadata

  • Download URL: StrEnum-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 4.3 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 484aa910792b43ba32fcc13cfbe539237180af7003a58d99d50cc158a58608ed
MD5 d51ad29febc7072b9ffbccccb77eedb4
BLAKE2b-256 4b041a92223fba2a1ef30aa8037582440bab41881e584eeef26b2a5c043fc55a

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