Notes

Creation

Create a note by instantiating Note:

note = Note(title="My note")

assert note.title == "My note"

Or use a Note subclass to implement custom interfaces, for example attribute accessors:

class MyNote(Note):
    
    @property
    def my_label(self) -> str:
        return self.labels.get_value("myLabel")
    
    @my_label.setter
    def my_label(self, val: str):
        self.labels.set_value("myLabel", val)

note = MyNote(title="My note")

note.my_label = "my_value"
assert note.my_label == "my_value"

Every created note must have at least one parent note. You can provide one or more during creation:

note = Note(parents=session.root)

The remaining examples assume that you will place the newly created note in your hierarchy by giving it a parent.

Entity bind operator: +=

Use += to add a Label, Relation, Branch (parent or child), or child Note.

Add a label:

note += Label("myLabel")
assert note.labels.get_value("myLabel") == ""

Add a relation:

note += Relation("myRelation", session.root)
assert note.relations.get_target("myRelation") is session.root

Add a child branch implicitly with empty prefix:

note += Note(title="Child note")
assert note.children[0].title == "Child note"

Add a child branch implicitly with prefix specified as tuple[Note, str]:

note += (Note(title="Child note"), "My prefix")
assert note.children[0].title == "Child note"

Or equivalently, explicitly create a Branch:

child = Note(title="Child note")
note += Branch(child=child, prefix="My prefix")

assert note.branches.children[0].prefix == "My prefix"
assert note.children[0] is child

Similarly, explicitly create a parent branch:

note += Branch(parent=session.root, prefix="My prefix")
assert note.branches.parents[0].prefix == "My prefix"

Clone operator: ^=

Use ^= to add another note as a parent, cloning it:

# get today's day note
today = session.get_today_note()

# clone to today
note ^= today

Specify a branch prefix by passing a tuple[Note, str]:

note ^= (today, "My prefix")

Content

To access note content, get or set Note.content. Content type should be str if Note.is_string is True, and bytes otherwise.

note = Note()
note.content = "<p>Hello, world!</p>"

assert note.content == "<p>Hello, world!</p>"

For type-safe access, use Note.content_str or Note.content_bin:

note = Note()
note.content_str = "<p>Hello, world!</p>"

assert note.content_str == "<p>Hello, world!</p>"

Note

Type-safe accessors will raise ValueError if the content is not of the expected type as determined by Note.is_string.