Attributes

As mentioned in Notes, one or more attributes can be added to a note via the += operator:

note += Label("myLabel")
note += [Label("myLabel2", "myValue2"), Relation("myRelation", other_note)]

The following sections describe other interfaces to access attributes.

Single-valued labels

Notes can be indexed to get/set an owned single-valued label, or specifically the first owned label matching the provided name. If no owned label with that name exists, a new one is created.

For example, to set #priority=10:

assert "priority" not in note

note["priority"] = "10"

assert "priority" in note
assert note["priority"] == "10"

Note does not implement a fully-featured dictionary, only dictionary-like semantics for single-valued labels.

Labels

Labels are accessed as Note.labels. For example, to get/set the first label with a given name:

assert "myLabel" not in note.labels
assert note.labels.get_value("myLabel") is None

note.labels.set_value("myLabel", "myValue1")

assert "myLabel" in note.labels
assert note.labels.get_value("myLabel") == "myValue1"

To get all labels with a given name:

assert len(note.labels.get_all("myLabel")) == 1
assert note.labels.get_values("myLabel") == ["myValue1"]

To filter by owned vs inherited, use:

Relations

Relations are accessed as Note.relations. For example, to get/set the first relation with a given name:

assert "myRelation" not in note.relations
assert note.relations.get_target("myRelation") is None

note.relations.set_target("myRelation", other_note)

assert "myRelation" in note.relations
assert note.relations.get_target("myLabel") is other_note

To get all relations with a given name:

assert len(note.relations.get_all("myRelation")) == 1
assert note.relations.get_targets("myRelation") == [other_note]

To filter by owned vs inherited, use:

Combined labels and relations

The combined list of labels and relations is accessed as: Note.attributes. It provides an interface similar to Note.labels and Note.relations.

To filter by owned vs inherited, use:

Note

Implementation detail: The latter two objects constitute the source of truth for attributes; all other interfaces simply map to these while providing type correctness.