Skip to main content

A small, dependency-free library that provides additional subclasses of enum.StrEnum

Project description

stringenum

PyPI - Version PyPI - Python Version License Checked with mypy Ruff

GitHub Workflow Status (with event) GitHub Actions Workflow Status codecov

Table Of Contents

About

A small, dependency-free library that provides additional subclasses of enum.StrEnum.

Installation

stringenum is available on PyPI, so you can simply use pip to install it.

pip install stringenum

Usage

  • stringenum.StrEnum - Identical to enum.StrEnum.

  • stringenum.CaseInsensitiveStrEnum - A subclass of StrEnum that supports case-insensitive lookup.

    >>> class Pet(CaseInsensitiveStrEnum):
    ...     CAT = "meow"
    ...     DOG = "bark"
    
    >>> Pet("Meow")
    <Pet.CAT: 'meow'>
    
    >>> Pet("BARK")     
    <Pet.DOG: 'bark'>
    
    >>> Pet["Cat"]
    <Pet.CAT: 'meow'>
    
    >>> Pet["dog"] 
    <Pet.DOG: 'bark'>
    
  • stringenum.DoubleSidedStrEnum - A subclass of StrEnum that supports double-sided lookup, allowing both member values and member names to be used for lookups. It also ensures that each member has a unique value.

    >>> class Status(DoubleSidedStrEnum):
    ...     PENDING = "waiting"
    ...     REJECTED = "denied"
    
    >>> Status("PENDING")
    <Status.PENDING: 'waiting'>
    
    >>> Status("waiting")
    <Status.PENDING: 'waiting'>
    
    >>> Status["REJECTED"]
    <Status.REJECTED: 'denied'>
    
    >>> Status["denied"]
    <Status.REJECTED: 'denied'>
    
  • stringenum.DoubleSidedCaseInsensitiveStrEnum - A subclass of StrEnum that supports case-insenitive double-sided lookup, allowing both member values and member names to be used for lookups. It also ensures that each member has a unique value.

    >>> class Status(DoubleSidedCaseInsensitiveStrEnum):
    ...     PENDING = "waiting"
    ...     REJECTED = "denied"
    
    >>> Status("pending")
    <Status.PENDING: 'waiting'>
    
    >>> Status("Waiting")
    <Status.PENDING: 'waiting'>
    
    >>> Status["Rejected"]
    <Status.REJECTED: 'denied'>
    
    >>> Status["DenieD"]
    <Status.REJECTED: 'denied'>
    

License

Distributed under the MIT License. See LICENSE for more information.

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

stringenum-0.2.0.tar.gz (22.3 kB view details)

Uploaded Source

Built Distribution

stringenum-0.2.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file stringenum-0.2.0.tar.gz.

File metadata

  • Download URL: stringenum-0.2.0.tar.gz
  • Upload date:
  • Size: 22.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for stringenum-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7c885aece7115a7558ff8396a93124f6063cfd19ca270df463df9d8ef9c0690d
MD5 ef34f927fbee278df777cb4a2aa27bb3
BLAKE2b-256 532ce0bfff23b06aff49156168920b74ccd2c79c2cdcfe55ceea17639f1fba5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for stringenum-0.2.0.tar.gz:

Publisher: release.yml on Ravencentric/stringenum

Attestations:

File details

Details for the file stringenum-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: stringenum-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for stringenum-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f8048274d95da6add099c0a8df42611076e78379641f1353f3c92539e138425a
MD5 0bf26ef7c5e3502502f4fb0eda9db5a6
BLAKE2b-256 db3c519f6e75814e23560a188cc6df1f2fb67a7f750593de03ae6e97a8aaa8dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for stringenum-0.2.0-py3-none-any.whl:

Publisher: release.yml on Ravencentric/stringenum

Attestations:

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