Skip to content

Feature request: partial loading using path-like specifier #910

@pdgendt

Description

@pdgendt

For use-cases where only part of a document is needed, it would be nice to be able to load and return early.

For an example document:

a:
  b:
    - x
    - y
    - z
  c:
    d: 42

We could partially load, for example:

print(load_part(yaml_text, ".a.c.d"))   # -> 42
print(load_part(yaml_text, ".a.b[1]"))  # -> "y"
print(load_part(yaml_text, ".a.c"))     # -> {'d': 42}
print(load_part(yaml_text, ".a.b"))     # -> ['x', 'y', 'z']
print(load_part(yaml_text, ".nonexistent"))  # -> None

Advantages (depending on usage of anchors):

  • Only materialize values that lie along the requested path.
  • Stop as soon as we finished building the value at that path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions