Abstract

Purpose

Nested data can be easily expressed in python but not easily accessed or modified. Using builtin methods, accessing nested data requires chaining dict.get() calls.

mydict.get("exterior", {}).get("color", {}).get("trim", {}) # wow bummer

This is overly verbose and lacks the functionality needed to effectively interact with the data. Delimited provides classes that emulate native types and make accessing and modifying nested data easier.

mydict.get("exterior.color.trim") # much better

Delimited provides Path classes to represent paths to nested data using tuples or strings, and NestedContainer classes that emulate the native dict and collections.OrderedDict types.

Terms

Nested data

Container type data that has other container types as values.

{
  "key1": {
    "key2": {
      "key3": "value"
    }
  }
}

Path

An group of path segments that represent a location within a nested data structure.

"key1.key2.key3"

Note

The example is using the collapsed path format of DelimitedStrPath

Path segment

A single part of a path representing a single location or level in a nested data structure.

DelimitedStrPath("key1.key2.key3")[1]

# "key2"

Collapsed path format

The type and format of a hashable iterable used by the _encode() and _decode() methods of Path objects. This is specific to the implementation of each Path subclass.

TuplePath

("key1", "key2", "key3")

DelimitedStrPath

"key1.key2.key3"

Tuple path notation

The collapsed path format of the TuplePath class.

("key1", "key2", "key3")

Delimited string path notation

The collapsed path format of the DelimitedStrPath class.

"key1.key2.key3"