Accessing Items with Index#

Use Index to look up notebooks, directories, and pages by ID, or to get every item with a given name.

Warning

coll["name"] returns the first match when names are duplicated. Use coll[Index.Id: "..."] to select one item by ID.

Supported Collection Types#

Index-based lookup is supported for:

Warning

Page Entries do not support Index slicing. Access entries by integer index, iteration, or entry ID string.

Note

Iterating over user.notebooks or a tree container yields names. Use values() for objects and items() for (name, object) pairs.

Basic Access by Name#

A string key looks up by name:

notebook = user.notebooks["My Research Notebook"]
experiments = notebook["Experiments"]

To include duplicates, call all_keys(), all_items(), or all_values() instead of keys(), items(), or values().

Explicit Indexing with Index#

Slice with Index to look up by ID or by name.

Access by ID#

from labapi import Index

notebook = user.notebooks[Index.Id:"12345"]
page = notebook[Index.Id:"67890"]

Access by Name#

from labapi import Index

shared_notebooks = user.notebooks[Index.Name:"Shared Data"]
protocols = experiments[Index.Name:"Protocol"]

Summary of Indexing Methods#

Syntax

Method

Returns

coll["name"]

Implicit name lookup

First item with matching name

coll[Index.Id: "id"]

Explicit ID lookup

The unique item with matching ID

coll[Index.Name: "n"]

Explicit name list lookup

A list of all items with matching name