Skip to main content

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 "->").

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.

Metadata

Release files for nested-inside 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nested-inside 0.2
File Size Uploaded Provenance
nested_inside-0.2.tar.gz 4.4 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for nested-inside 0.2
File Interpreter ABI Platform
nested_inside-0.2-py3-none-any.whl Python 3 none any Details

Total release size: 10.0 kB

Release files / nested_inside-0.2.tar.gz

Download URL nested_inside-0.2.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1af8ca353b43e1776df145b1457af9bc33902279e687239f827f874e1b959aea
BLAKE2b-256 checksum
How to use checksums
647b22b0cb90ab88c87dbb9cf5776338b597f0f0bd4de1095254472915dffc37
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Release files / nested_inside-0.2-py3-none-any.whl

Download URL nested_inside-0.2-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f44f3361c35eaed8967ede94faad64a767846fff7989dbdd11ff7768059c077
BLAKE2b-256 checksum
How to use checksums
d0be69cb88c74200d7b74e941557cb9708417ff7ae947bd239fcde9666403f00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.8.10

Security for nested-inside 0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page