nested-inside


Namenested-inside JSON
Version 0.2 PyPI version JSON
download
home_pagehttps://github.com/MrDebugger/nested_inside
SummaryA nested data structure for accessing and modifying values using a delimiter
upload_time2023-01-15 18:21:32
maintainer
docs_urlNone
authorIjaz Ur Rahim
requires_python>=3.6
licenseMIT
keywords parser json dict nested nested_dict nested_list nested_tuple tuple list nested_inside
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Nested Inside

The `Nested Inside` package provides a nested data structure that allows for easy and intuitive access and modification of nested data. The package defines a `Nested` class that wraps a data structure (e.g. a dictionary, list, or tuple) and allows for nested access using a specified delimiter (default "->"). The class provides several methods such as `get`, `set`, `parse` to access and modify the nested data, and also provides derived classes such as `NestedDict`, `NestedList`, and `NestedTuple` to return the data in a modifiable or immutable format. This package can be especially useful when working with complex data structures that contain multiple nested levels, as it allows you to access and modify the data using a simple key path instead of having to navigate through multiple levels of nested data manually.

## Installation

To install the package, use pip:

```
pip install nested_inside
```


## Usage

The package provides a `Nested` class that wraps a data structure (e.g. a dictionary, list, or tuple) and allows for nested access using a specified delimiter (default "->").

```python
from nested_inside import NestedDict

data = {
    "a": {
        "b": [1, 2, 3],
        "c": "hello"
    }
}
nested_data = NestedDict(data)

# Accessing nested values using get function
value = nested_data.get("a->b->0")
print(value) # 1

# Modifying nested values using set function
nested_data.set("a->b->0", 4)
# modify or access data using [] syntax
nested_data['a->b->1'] = 3
# modify or access data using object call
nested_data('a->b->2', 4)
# modify or access data using dot notation
nested_data.a.c = "world"

print(nested_data.a.b) # [4, 3, 4]
# call object without any parameter to retrieve data
print(nested_data('a->c'))

# Retrieving default value by providing value to default
value = nested_data("a->d", default="not found")
print(value) # "not found"

# Return mutable object
value = nested_data.get("a", modify=True)
# provide tuple as key to modify
value[["b"]] = [5, 6, 7]

# provide tuple as key
print(nested_data.get(("a","b"))) # [5, 6, 7]

# provide list as key
print(nested_data[["a","b", 2]]) # 7

# provide list as key with index as string
print(nested_data[["a","b", "0"]]) # 5

```

## Methods

- `__init__(self, data: Any, delimiter: str = "->")`: Initialize a new Nested object with the given data and delimiter.
- `parse(self, value: Any, modify: bool = False) -> Any`: A helper function that converts the value to a modifiable or immutable object based on the 'modify' flag
- `get(self, key: Union[int, str, list, tuple, None], default=NODEFAULT, modify: bool = False) -> Any`: Retrieves the value stored at the specified key path in the nested data structure.
- `set(self, key: Union[int, str, list, tuple], value: Any) -> None`: Set the value stored at the specified key path in the nested data structure.

## Contributing

If you would like to contribute to the package, feel free to submit a pull request.

## License

The package is licensed under the MIT License.




            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/MrDebugger/nested_inside",
    "name": "nested-inside",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "parser,json,dict,nested,nested_dict,nested_list,nested_tuple,tuple,list,nested_inside",
    "author": "Ijaz Ur Rahim",
    "author_email": "ijazkhan095@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/64/7b/22b0cb90ab88c87dbb9cf5776338b597f0f0bd4de1095254472915dffc37/nested_inside-0.2.tar.gz",
    "platform": null,
    "description": "# Nested Inside\n\nThe `Nested Inside` package provides a nested data structure that allows for easy and intuitive access and modification of nested data. The package defines a `Nested` class that wraps a data structure (e.g. a dictionary, list, or tuple) and allows for nested access using a specified delimiter (default \"->\"). The class provides several methods such as `get`, `set`, `parse` to access and modify the nested data, and also provides derived classes such as `NestedDict`, `NestedList`, and `NestedTuple` to return the data in a modifiable or immutable format. This package can be especially useful when working with complex data structures that contain multiple nested levels, as it allows you to access and modify the data using a simple key path instead of having to navigate through multiple levels of nested data manually.\n\n## Installation\n\nTo install the package, use pip:\n\n```\npip install nested_inside\n```\n\n\n## Usage\n\nThe package provides a `Nested` class that wraps a data structure (e.g. a dictionary, list, or tuple) and allows for nested access using a specified delimiter (default \"->\").\n\n```python\nfrom nested_inside import NestedDict\n\ndata = {\n    \"a\": {\n        \"b\": [1, 2, 3],\n        \"c\": \"hello\"\n    }\n}\nnested_data = NestedDict(data)\n\n# Accessing nested values using get function\nvalue = nested_data.get(\"a->b->0\")\nprint(value) # 1\n\n# Modifying nested values using set function\nnested_data.set(\"a->b->0\", 4)\n# modify or access data using [] syntax\nnested_data['a->b->1'] = 3\n# modify or access data using object call\nnested_data('a->b->2', 4)\n# modify or access data using dot notation\nnested_data.a.c = \"world\"\n\nprint(nested_data.a.b) # [4, 3, 4]\n# call object without any parameter to retrieve data\nprint(nested_data('a->c'))\n\n# Retrieving default value by providing value to default\nvalue = nested_data(\"a->d\", default=\"not found\")\nprint(value) # \"not found\"\n\n# Return mutable object\nvalue = nested_data.get(\"a\", modify=True)\n# provide tuple as key to modify\nvalue[[\"b\"]] = [5, 6, 7]\n\n# provide tuple as key\nprint(nested_data.get((\"a\",\"b\"))) # [5, 6, 7]\n\n# provide list as key\nprint(nested_data[[\"a\",\"b\", 2]]) # 7\n\n# provide list as key with index as string\nprint(nested_data[[\"a\",\"b\", \"0\"]]) # 5\n\n```\n\n## Methods\n\n- `__init__(self, data: Any, delimiter: str = \"->\")`: Initialize a new Nested object with the given data and delimiter.\n- `parse(self, value: Any, modify: bool = False) -> Any`: A helper function that converts the value to a modifiable or immutable object based on the 'modify' flag\n- `get(self, key: Union[int, str, list, tuple, None], default=NODEFAULT, modify: bool = False) -> Any`: Retrieves the value stored at the specified key path in the nested data structure.\n- `set(self, key: Union[int, str, list, tuple], value: Any) -> None`: Set the value stored at the specified key path in the nested data structure.\n\n## Contributing\n\nIf you would like to contribute to the package, feel free to submit a pull request.\n\n## License\n\nThe package is licensed under the MIT License.\n\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A nested data structure for accessing and modifying values using a delimiter",
    "version": "0.2",
    "split_keywords": [
        "parser",
        "json",
        "dict",
        "nested",
        "nested_dict",
        "nested_list",
        "nested_tuple",
        "tuple",
        "list",
        "nested_inside"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d0be69cb88c74200d7b74e941557cb9708417ff7ae947bd239fcde9666403f00",
                "md5": "ae5187b5e0f92f7d3a15ad33d7668f04",
                "sha256": "8f44f3361c35eaed8967ede94faad64a767846fff7989dbdd11ff7768059c077"
            },
            "downloads": -1,
            "filename": "nested_inside-0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ae5187b5e0f92f7d3a15ad33d7668f04",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 5526,
            "upload_time": "2023-01-15T18:21:30",
            "upload_time_iso_8601": "2023-01-15T18:21:30.419136Z",
            "url": "https://files.pythonhosted.org/packages/d0/be/69cb88c74200d7b74e941557cb9708417ff7ae947bd239fcde9666403f00/nested_inside-0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "647b22b0cb90ab88c87dbb9cf5776338b597f0f0bd4de1095254472915dffc37",
                "md5": "8aec63e07ba50998ba418430b74e1ce0",
                "sha256": "1af8ca353b43e1776df145b1457af9bc33902279e687239f827f874e1b959aea"
            },
            "downloads": -1,
            "filename": "nested_inside-0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "8aec63e07ba50998ba418430b74e1ce0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 4430,
            "upload_time": "2023-01-15T18:21:32",
            "upload_time_iso_8601": "2023-01-15T18:21:32.124960Z",
            "url": "https://files.pythonhosted.org/packages/64/7b/22b0cb90ab88c87dbb9cf5776338b597f0f0bd4de1095254472915dffc37/nested_inside-0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-01-15 18:21:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "MrDebugger",
    "github_project": "nested_inside",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "nested-inside"
}
        
Elapsed time: 0.02973s