Contributor Architecture Guide#
This page describes how the tree, entry, and client internals of labapi
currently behave, including where the design is intentionally incomplete.
Subsystem Map#
A call passes through these layers:
Tree model (
Notebooks->Notebook->NotebookDirectory/NotebookPage)Utility layer (
labapi.utilhelpers such asNotebookPath, indexing types, and XML extraction)
Client and User Boundary#
Client handles the connection, authentication, and
request signing. It appends the AKID, expiry, and HMAC-SHA512 signature to
each request URL.
User wraps an authenticated session and provides
api_get()/api_post() that always
add uid. Most internal modules call the API through
User rather than directly through
Client.
Tree Model Boundary#
The tree model is split between mapping-style collections and node/container mixins:
Notebookstracks the user-visible notebook list.Notebookis both the logical root and a container.NotebookDirectoryis a container node.NotebookPageis a leaf node with lazy-loaded entries.
Most operations that mutate the notebook hierarchy are implemented in
tree/mixins.py and then reused by concrete node types.
Entry Model Boundary#
entries lazily fetches page entries and
materializes them as Entry subclasses.
The Entries collection owns page-level entry
creation methods and appends newly created entries to local state after
successful API calls.
Utility Layer Boundary#
The labapi.util package provides primitives that are shared by tree,
entry, and client modules:
NotebookPathpath normalization/resolutiontyped index markers (
Index.Id/Index.Name)XML extraction and conversion helpers
environment and browser-detection helpers (
getenv,detect_default_browser)
Cache model and invariants#
Container Population Cache (_populated)#
AbstractTreeContainer lazily loads children on
first access:
Page Entries Cache (_entries)#
entries is also lazy:
Path Cache (_has_path)#
Every tree node memoizes its NotebookPath:
first
pathaccess computes and caches aNotebookPathfor the node.rename and move operations clear the cached path for the current node and any loaded descendants.
Path Stability and Traversal Expectations#
NotebookPath normalizes path input. A path can be
absolute or relative, joined to another with /, resolved against a parent
path, and made relative with
relative_to().
traverse() resolves relative
paths against self.path and then walks segments from self.root.
Enumeration helpers build on the same traversal model:
enumerate_nodes()returns(relative_path, node)pairs for concrete descendant objects.enumerate_all(),enumerate_dirs(), andenumerate_pages()derive from that shared traversal so duplicate names do not get re-resolved throughtraverse().
Mutation Invariants and Refresh Expectations#
General Rule#
Mutating methods first call the API and then update local in-memory state when the API call succeeds.
Create Operations#
create() inserts new nodes and
appends them to self._children. For container nodes, the new node starts
with _populated=True and empty children.
When if_exists=InsertBehavior.Replace, existing matching nodes are deleted
before creating a replacement.
Move Operations#
move_to() updates the server parent,
then mutates both local parents:
removes the node from old parent
_childrenswitches
_parentappends to destination
_childrenif the destination is already populatedinvalidates cached paths for the moved node and any loaded descendants
Delete Operations#
delete() moves the node to a trash
folder:
ensure/create an
API Deleted Itemsdirectory under notebook rootrename node to include deletion timestamp
call
move_to()with the trash folder as destination
The Python object stays the same, with its new parent and new name.
When to Call Refresh#
Use refresh() (or
refresh() for page entries) before reading
changes made by another user, the web UI, or another API session, or when you
need to force a re-fetch.
By design, refresh() only clears the container’s child cache or the page’s
entries cache. Child and entry objects you already hold are not updated.
Other Entry Types#
When page entries are loaded, unrecognized part types are wrapped as
UnknownEntry and
recognized-but-unimplemented types as
UnimplementedEntry, with warnings in
entries.
Known Limitations and TODOs#
individual entry deletion is not implemented
create_json_entry()creates anAttachmentEntryand aTextEntry; no wrapper object represents the pair
Contributor Checklist for Internal Changes#
Before changing tree/entry/client internals:
Identify which cache invariants your change touches (
_populated,_entries,_has_path).Decide whether in-memory objects must be mutated immediately or whether
refresh()/refresh()should be required.Ensure parent/child bookkeeping stays symmetric for moves/deletes.
If you add or change entry types, confirm entry registration plus
from_part_type()dispatch behavior.