enum-extension


Nameenum-extension JSON
Version 1.0.1 PyPI version JSON
download
home_page
SummaryPython library that extends the functionality of the built-in enum module,
upload_time2023-06-04 16:50:56
maintainer
docs_urlNone
author
requires_python>=3.6
licenseMIT License Copyright (c) 2023 Muhammad Ali Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords enum extension python enhancements utilities advanced capabilities
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Enum Extension


![Python Version](https://img.shields.io/badge/PythonVersion-%3E%3D3.6-blue)
![Licence](https://img.shields.io/github/license/m-ali-ubit/enum-extension?style=plastic)
![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/m-ali-ubit/enum-extension/ci.yml?style=plastic)
![Code Formatting](https://img.shields.io/badge/CodeFormatting-Black-blue)
![Code Styling](https://img.shields.io/badge/CodeStyling-Pylint-blue)
![Code Styling](https://img.shields.io/badge/CodeStyling-PEP8-blue)
![Code Styling](https://img.shields.io/badge/CodeStyling-Flake8-blue)
![GitHub last commit](https://img.shields.io/github/last-commit/m-ali-ubit/enum-extension?style=plastic)
![GitHub top language](https://img.shields.io/github/languages/top/m-ali-ubit/enum-extension?style=plastic)

enum-extension is a Python library that extends the functionality of the built-in enum module,
offering an array of additional features and utilities to simplify enumeration handling and expand its capabilities.

## Installation
You can install enum-extension using pip:

`pip install enum-extension`

## Description

The enum-extension library enhances the native enum module in Python, providing additional functionality for enumerations.
It introduces the StringEnum class, which inherits from the standard enum.Enum and extends its capabilities.
With enum-extension, you can perform bitwise operations such as OR, AND, and NOT on string type enum values,
combine multiple enums into a single variable, and easily check for membership within combined enums.

## Usage

Here are some examples of how to use StringEnum:

```python
from enum_extensions import StringEnum

# Create an enum by inheriting from StringEnum
class PaymentMethod(StringEnum):
    VISA = "VISA"
    MASTERCARD = "MASTERCARD"
    APPLE_PAY = "APPLE_PAY"
    GOOGLE_PAY = "GOOGLE_PAY"
    VENMO = "VENMO"
    PAYPAL = "PAYPAL"

# Use | to combine two enums into one
CARDS = PaymentMethod.MASTERCARD | PaymentMethod.VISA   # PaymentMethod.MASTERCARD|VISA

# Use ~ to get the opposite values of an enum
WALLETS = ~CARDS   # PaymentMethod.APPLE_PAY|GOOGLE_PAY|PAYPAL|VENMO

# Use & operator to check for membership of an enum in the combined enum
PaymentMethod.MASTERCARD & CARDS  # True
PaymentMethod.VISA & CARDS        # True
PaymentMethod.VENMO & CARDS       # False

# Check membership using a string value with & operator (case-insensitive)
CARDS & "Visa"   # True
CARDS & "visa"   # True

# Check string with enum value as a comparison
PaymentMethod.VISA & "visa"    # True
PaymentMethod.PAYPAL & "VISA"  # False

# Use comparison operator to check for equality
PaymentMethod.VISA == "visa"   # True
PaymentMethod.PAYPAL == "VISA"  # False

paypal1 = PaymentMethod.PAYPAL
paypal2 = PaymentMethod.PAYPAL
paypal1 == paypal2    # True

# Create multiple enum classes and merge their values
class CardProvider(StringEnum):
    VISA = "VISA"
    MASTERCARD = "MASTERCARD"

class WalletProvider(StringEnum):
    VENMO = "VENMO"
    PAYPAL = "PAYPAL"

CARD_PROVIDERS = CardProvider.MASTERCARD | CardProvider.VISA      # CardProvider.MASTERCARD|VISA
WALLET_PROVIDERS = WalletProvider.VENMO | WalletProvider.PAYPAL   # WalletProvider.PAYPAL|VENMO

# Merge two separate StringEnum class values
ALL_METHODS = CARD_PROVIDERS | WALLET_PROVIDERS    # CardProvider_WalletProvider.MASTERCARD|PAYPAL|VENMO|VISA

# Check for membership with the merged enum
WalletProvider.VENMO & WALLET_PROVIDERS    # True
CardProvider.MASTERCARD & ALL_METHODS      # True

# Please note that the merge and combine operations do not modify the original enum definitions but create new enum values.
```

If you have any suggestions or feature requests, please feel free to contribute or reach out.

### License

This project is licensed under the MIT License - see the LICENSE file for details.

Hope you find enum-extension helpful and convenient for working with enumerations in Python.

If you encounter any issues or have any questions, please don't hesitate to open an issue on [GitHub](https://github.com/m-ali-ubit/enum-extension/issues).

This package is owned and maintained by [m-ali-ubit](https://github.com/m-ali-ubit).

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "enum-extension",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "enum,extension,python,enhancements,utilities,advanced,capabilities",
    "author": "",
    "author_email": "MuhammadAli <usermalikhan@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/f3/1d/bf4da599ffdf58eca2a0e609e15df9f919d94f81ae1935c846df5957c514/enum-extension-1.0.1.tar.gz",
    "platform": null,
    "description": "# Enum Extension\n\n\n![Python Version](https://img.shields.io/badge/PythonVersion-%3E%3D3.6-blue)\n![Licence](https://img.shields.io/github/license/m-ali-ubit/enum-extension?style=plastic)\n![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/m-ali-ubit/enum-extension/ci.yml?style=plastic)\n![Code Formatting](https://img.shields.io/badge/CodeFormatting-Black-blue)\n![Code Styling](https://img.shields.io/badge/CodeStyling-Pylint-blue)\n![Code Styling](https://img.shields.io/badge/CodeStyling-PEP8-blue)\n![Code Styling](https://img.shields.io/badge/CodeStyling-Flake8-blue)\n![GitHub last commit](https://img.shields.io/github/last-commit/m-ali-ubit/enum-extension?style=plastic)\n![GitHub top language](https://img.shields.io/github/languages/top/m-ali-ubit/enum-extension?style=plastic)\n\nenum-extension is a Python library that extends the functionality of the built-in enum module,\noffering an array of additional features and utilities to simplify enumeration handling and expand its capabilities.\n\n## Installation\nYou can install enum-extension using pip:\n\n`pip install enum-extension`\n\n## Description\n\nThe enum-extension library enhances the native enum module in Python, providing additional functionality for enumerations.\nIt introduces the StringEnum class, which inherits from the standard enum.Enum and extends its capabilities.\nWith enum-extension, you can perform bitwise operations such as OR, AND, and NOT on string type enum values,\ncombine multiple enums into a single variable, and easily check for membership within combined enums.\n\n## Usage\n\nHere are some examples of how to use StringEnum:\n\n```python\nfrom enum_extensions import StringEnum\n\n# Create an enum by inheriting from StringEnum\nclass PaymentMethod(StringEnum):\n    VISA = \"VISA\"\n    MASTERCARD = \"MASTERCARD\"\n    APPLE_PAY = \"APPLE_PAY\"\n    GOOGLE_PAY = \"GOOGLE_PAY\"\n    VENMO = \"VENMO\"\n    PAYPAL = \"PAYPAL\"\n\n# Use | to combine two enums into one\nCARDS = PaymentMethod.MASTERCARD | PaymentMethod.VISA   # PaymentMethod.MASTERCARD|VISA\n\n# Use ~ to get the opposite values of an enum\nWALLETS = ~CARDS   # PaymentMethod.APPLE_PAY|GOOGLE_PAY|PAYPAL|VENMO\n\n# Use & operator to check for membership of an enum in the combined enum\nPaymentMethod.MASTERCARD & CARDS  # True\nPaymentMethod.VISA & CARDS        # True\nPaymentMethod.VENMO & CARDS       # False\n\n# Check membership using a string value with & operator (case-insensitive)\nCARDS & \"Visa\"   # True\nCARDS & \"visa\"   # True\n\n# Check string with enum value as a comparison\nPaymentMethod.VISA & \"visa\"    # True\nPaymentMethod.PAYPAL & \"VISA\"  # False\n\n# Use comparison operator to check for equality\nPaymentMethod.VISA == \"visa\"   # True\nPaymentMethod.PAYPAL == \"VISA\"  # False\n\npaypal1 = PaymentMethod.PAYPAL\npaypal2 = PaymentMethod.PAYPAL\npaypal1 == paypal2    # True\n\n# Create multiple enum classes and merge their values\nclass CardProvider(StringEnum):\n    VISA = \"VISA\"\n    MASTERCARD = \"MASTERCARD\"\n\nclass WalletProvider(StringEnum):\n    VENMO = \"VENMO\"\n    PAYPAL = \"PAYPAL\"\n\nCARD_PROVIDERS = CardProvider.MASTERCARD | CardProvider.VISA      # CardProvider.MASTERCARD|VISA\nWALLET_PROVIDERS = WalletProvider.VENMO | WalletProvider.PAYPAL   # WalletProvider.PAYPAL|VENMO\n\n# Merge two separate StringEnum class values\nALL_METHODS = CARD_PROVIDERS | WALLET_PROVIDERS    # CardProvider_WalletProvider.MASTERCARD|PAYPAL|VENMO|VISA\n\n# Check for membership with the merged enum\nWalletProvider.VENMO & WALLET_PROVIDERS    # True\nCardProvider.MASTERCARD & ALL_METHODS      # True\n\n# Please note that the merge and combine operations do not modify the original enum definitions but create new enum values.\n```\n\nIf you have any suggestions or feature requests, please feel free to contribute or reach out.\n\n### License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n\nHope you find enum-extension helpful and convenient for working with enumerations in Python.\n\nIf you encounter any issues or have any questions, please don't hesitate to open an issue on [GitHub](https://github.com/m-ali-ubit/enum-extension/issues).\n\nThis package is owned and maintained by [m-ali-ubit](https://github.com/m-ali-ubit).\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023 Muhammad Ali  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Python library that extends the functionality of the built-in enum module,",
    "version": "1.0.1",
    "project_urls": {
        "homepage": "https://github.com/m-ali-ubit/enum-extension",
        "repository": "https://github.com/m-ali-ubit/enum-extension"
    },
    "split_keywords": [
        "enum",
        "extension",
        "python",
        "enhancements",
        "utilities",
        "advanced",
        "capabilities"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "900eb8807a19550112bfcb173fbb520f2a6b73fe2e0c89031a1129f14dfcff5e",
                "md5": "657377795fb5f2fdbd53e66705f88c95",
                "sha256": "fc39287013dfb321869bb3b666444856d32f802e7c768c9b1e6f76a757c926e3"
            },
            "downloads": -1,
            "filename": "enum_extension-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "657377795fb5f2fdbd53e66705f88c95",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 7301,
            "upload_time": "2023-06-04T16:50:54",
            "upload_time_iso_8601": "2023-06-04T16:50:54.702579Z",
            "url": "https://files.pythonhosted.org/packages/90/0e/b8807a19550112bfcb173fbb520f2a6b73fe2e0c89031a1129f14dfcff5e/enum_extension-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f31dbf4da599ffdf58eca2a0e609e15df9f919d94f81ae1935c846df5957c514",
                "md5": "b1992dc95516570c55a8a2bdb7f7e628",
                "sha256": "f7963a29e7d2c03f46805482579449ce066a6f2934e51a40ffb5ed4948f98cec"
            },
            "downloads": -1,
            "filename": "enum-extension-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "b1992dc95516570c55a8a2bdb7f7e628",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 9053,
            "upload_time": "2023-06-04T16:50:56",
            "upload_time_iso_8601": "2023-06-04T16:50:56.341955Z",
            "url": "https://files.pythonhosted.org/packages/f3/1d/bf4da599ffdf58eca2a0e609e15df9f919d94f81ae1935c846df5957c514/enum-extension-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-04 16:50:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "m-ali-ubit",
    "github_project": "enum-extension",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "enum-extension"
}
        
Elapsed time: 0.65669s