is_subset


Nameis_subset JSON
Version 0.1.1 PyPI version JSON
download
home_pageNone
Summarycheck if a given dictionary is subset of provided predicate
upload_time2024-11-25 22:00:16
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords is-subset python subset
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # is_subset

[![GPLv2 License](https://img.shields.io/badge/License-GPL%20v2-blue.svg)](https://opensource.org/licenses/) ![PyPI](https://img.shields.io/pypi/v/is_subset) [![Actions Status](https://github.com/WajahatAliAbid/is-subset/workflows/Build/badge.svg)](https://github.com/WajahatAliAbid/is-subset/actions)


**`is_subset`** is a Python utility for checking if a given dictionary (`dict2`) is a subset of another dictionary (`dict1`). It supports advanced matching features such as nested dictionaries, regular expressions, and conditional operators.



## Installation

Install my-project with pip

```bash
pip install is_subset
```
    
## Features

- Check if one dictionary (`dict2`) is a subset of another dictionary (`dict1`).
- Supports:
  - Exact matches
  - Nested dictionaries
  - Conditional checks like `__is`, `__not`, `__in`, `__not_in`, `__matches`, and `__not_matches`.
- Works seamlessly with Python primitives like strings, numbers, booleans, and collections.


## Usage

You can check if a dictionary is subset of another using

### Basic Examples
```python
from is_subset import is_subset

# Simple matching
dict1 = {"age": 30, "name": "John"}

dict2 = {"age": 30}
print(is_subset(dict1, dict2))  # Output: True

dict2 = {"age": 25}
print(is_subset(dict1, dict2))  # Output: False
```

### Advanced Examples
Nested Dictionary Matching
```python
dict1 = {
    "user": {
        "name": "John",
        "details": {
            "age": 30,
            "city": "Metropolis"
        }
    }
}

dict2 = {"user": {"details": {"city": "Metropolis"}}}
print(is_subset(dict1, dict2))  # Output: True
```

Conditional Matching (__is, __not, __in, __not_in)
```python
# Conditional matching for exact values
dict2 = {"user": {"details": {"city": {"__is": "Metropolis"}}}}
print(is_subset(dict1, dict2))  # Output: True

# Conditional matching for exclusion
dict2 = {"user": {"details": {"city": {"__not": "Gotham"}}}}
print(is_subset(dict1, dict2))  # Output: True

# Conditional matching for inclusion in a list
dict2 = {"user": {"details": {"age": {"__in": [25, 30]}}}}
print(is_subset(dict1, dict2))  # Output: True

# Conditional matching for exclusion in list

dict2 = {"user": {"details": {"age": {"__not_in": [20, 23]}}}}
print(is_subset(dict1, dict2))  # Output: True
```

Regular Expression Matching (__matches, __not_matches)
```python
dict1 = {"email": "john.doe@example.com"}

# Regex matching
dict2 = {"email": {"__matches": r".*@example\.com"}}
print(is_subset(dict1, dict2))  # Output: True

# Negative regex matching
dict2 = {"email": {"__not_matches": r".*@gmail\.com"}}
print(is_subset(dict1, dict2))  # Output: True
```


## API Reference
`is_subset(dict1: dict, dict2: dict) -> bool`

**Parameters**:
- `dict1` (`dict`): The main dictionary to check against.
- `dict2` (`dict`): A dictionary specifying the conditions to check.

**Returns**:
- `bool`: `True` if all conditions in `dict2` match the `dict1`, otherwise `False`.

**Supported Condition Operators**:
- `__is`: Matches if the value is equal.
- `__not`: Matches if the value is not equal.
- `__in`: Matches if the value is in a list or collection.
- `__not_in`: Matches if the value is not in a list or collection.
- `__matches`: Matches if the value satisfies the given regex.
- `__not_matches`: Matches if the value does not satisfy the given regex.

## Contributing

Contributions are always welcome! In case you have any request or encounter a bug, please create an issue on the repo.

## Authors

- [@WajahatAliAbid](https://www.github.com/WajahatAliAbid)


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "is_subset",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "is-subset, python, subset",
    "author": null,
    "author_email": "WajahatAliAbid <17341777+WajahatAliAbid@users.noreply.github.com>",
    "download_url": "https://files.pythonhosted.org/packages/a5/e6/148e0c885a4fd10b4e4a5cf2fd18e3c8b3a9a2e8cd414d68a43399fbda5e/is_subset-0.1.1.tar.gz",
    "platform": null,
    "description": "# is_subset\n\n[![GPLv2 License](https://img.shields.io/badge/License-GPL%20v2-blue.svg)](https://opensource.org/licenses/) ![PyPI](https://img.shields.io/pypi/v/is_subset) [![Actions Status](https://github.com/WajahatAliAbid/is-subset/workflows/Build/badge.svg)](https://github.com/WajahatAliAbid/is-subset/actions)\n\n\n**`is_subset`** is a Python utility for checking if a given dictionary (`dict2`) is a subset of another dictionary (`dict1`). It supports advanced matching features such as nested dictionaries, regular expressions, and conditional operators.\n\n\n\n## Installation\n\nInstall my-project with pip\n\n```bash\npip install is_subset\n```\n    \n## Features\n\n- Check if one dictionary (`dict2`) is a subset of another dictionary (`dict1`).\n- Supports:\n  - Exact matches\n  - Nested dictionaries\n  - Conditional checks like `__is`, `__not`, `__in`, `__not_in`, `__matches`, and `__not_matches`.\n- Works seamlessly with Python primitives like strings, numbers, booleans, and collections.\n\n\n## Usage\n\nYou can check if a dictionary is subset of another using\n\n### Basic Examples\n```python\nfrom is_subset import is_subset\n\n# Simple matching\ndict1 = {\"age\": 30, \"name\": \"John\"}\n\ndict2 = {\"age\": 30}\nprint(is_subset(dict1, dict2))  # Output: True\n\ndict2 = {\"age\": 25}\nprint(is_subset(dict1, dict2))  # Output: False\n```\n\n### Advanced Examples\nNested Dictionary Matching\n```python\ndict1 = {\n    \"user\": {\n        \"name\": \"John\",\n        \"details\": {\n            \"age\": 30,\n            \"city\": \"Metropolis\"\n        }\n    }\n}\n\ndict2 = {\"user\": {\"details\": {\"city\": \"Metropolis\"}}}\nprint(is_subset(dict1, dict2))  # Output: True\n```\n\nConditional Matching (__is, __not, __in, __not_in)\n```python\n# Conditional matching for exact values\ndict2 = {\"user\": {\"details\": {\"city\": {\"__is\": \"Metropolis\"}}}}\nprint(is_subset(dict1, dict2))  # Output: True\n\n# Conditional matching for exclusion\ndict2 = {\"user\": {\"details\": {\"city\": {\"__not\": \"Gotham\"}}}}\nprint(is_subset(dict1, dict2))  # Output: True\n\n# Conditional matching for inclusion in a list\ndict2 = {\"user\": {\"details\": {\"age\": {\"__in\": [25, 30]}}}}\nprint(is_subset(dict1, dict2))  # Output: True\n\n# Conditional matching for exclusion in list\n\ndict2 = {\"user\": {\"details\": {\"age\": {\"__not_in\": [20, 23]}}}}\nprint(is_subset(dict1, dict2))  # Output: True\n```\n\nRegular Expression Matching (__matches, __not_matches)\n```python\ndict1 = {\"email\": \"john.doe@example.com\"}\n\n# Regex matching\ndict2 = {\"email\": {\"__matches\": r\".*@example\\.com\"}}\nprint(is_subset(dict1, dict2))  # Output: True\n\n# Negative regex matching\ndict2 = {\"email\": {\"__not_matches\": r\".*@gmail\\.com\"}}\nprint(is_subset(dict1, dict2))  # Output: True\n```\n\n\n## API Reference\n`is_subset(dict1: dict, dict2: dict) -> bool`\n\n**Parameters**:\n- `dict1` (`dict`): The main dictionary to check against.\n- `dict2` (`dict`): A dictionary specifying the conditions to check.\n\n**Returns**:\n- `bool`: `True` if all conditions in `dict2` match the `dict1`, otherwise `False`.\n\n**Supported Condition Operators**:\n- `__is`: Matches if the value is equal.\n- `__not`: Matches if the value is not equal.\n- `__in`: Matches if the value is in a list or collection.\n- `__not_in`: Matches if the value is not in a list or collection.\n- `__matches`: Matches if the value satisfies the given regex.\n- `__not_matches`: Matches if the value does not satisfy the given regex.\n\n## Contributing\n\nContributions are always welcome! In case you have any request or encounter a bug, please create an issue on the repo.\n\n## Authors\n\n- [@WajahatAliAbid](https://www.github.com/WajahatAliAbid)\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "check if a given dictionary is subset of provided predicate",
    "version": "0.1.1",
    "project_urls": {
        "Changelog": "https://github.com/WajahatAliAbid/is-subset/blob/main/CHANGELOG.md",
        "Repository": "https://github.com/WajahatAliAbid/is-subset"
    },
    "split_keywords": [
        "is-subset",
        " python",
        " subset"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "fe0b3d4793b411bd1c3860f571dc866532409819158cc9fb95b0634e0850dfdf",
                "md5": "765c451479aeaf0b9ae119beffe49876",
                "sha256": "bc6a49d8e76c824a9cb5e559f97d7eae90457d12c6ae70e7fe6e2dbb6d5e1687"
            },
            "downloads": -1,
            "filename": "is_subset-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "765c451479aeaf0b9ae119beffe49876",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 11248,
            "upload_time": "2024-11-25T22:00:14",
            "upload_time_iso_8601": "2024-11-25T22:00:14.646266Z",
            "url": "https://files.pythonhosted.org/packages/fe/0b/3d4793b411bd1c3860f571dc866532409819158cc9fb95b0634e0850dfdf/is_subset-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "a5e6148e0c885a4fd10b4e4a5cf2fd18e3c8b3a9a2e8cd414d68a43399fbda5e",
                "md5": "6a9f16054214a71cbd6af6c198d310ab",
                "sha256": "2d26bd2130c1b7593d1049b27a11301aa9bae5b41a03c84773100b96b73cff18"
            },
            "downloads": -1,
            "filename": "is_subset-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "6a9f16054214a71cbd6af6c198d310ab",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 42151,
            "upload_time": "2024-11-25T22:00:16",
            "upload_time_iso_8601": "2024-11-25T22:00:16.301887Z",
            "url": "https://files.pythonhosted.org/packages/a5/e6/148e0c885a4fd10b4e4a5cf2fd18e3c8b3a9a2e8cd414d68a43399fbda5e/is_subset-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-25 22:00:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "WajahatAliAbid",
    "github_project": "is-subset",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "is_subset"
}
        
Elapsed time: 1.41061s