Skip to content

notion-objects 0.6.0

Latest
Compare
Choose a tag to compare
@thrau thrau released this 31 Mar 16:57
· 3 commits to main since this release

This release brings additional querying facilities, and support for relation property, rich text, and setting object IDs.

Querying by value

Database now adds two additional querying methods:

  • query_by_value
  • find_unique_by_value

With a database like this:

class TestRecord(Page):
    name = TitleText()
    some_id = Integer()
    some_value = Text()

database: Database[TestRecord] = Database(TestRecord, ...)

You can perform the following search operation to return all records that have foobar set in their text property some_value.

for record in database.query_by_value(TestRecord.some_value, "foobar"):
    print(record.to_dict())

If you expect a unique value (like some ID value), then you can use:

record = database.find_unique_by_value(TestRecord.some_id, 12345)
assert record is not None

Relation properties

A simple implementation of the Relation property is now available. It simply outputs and accepts UUIDs of other pages.

class Task(Page):
    Project = Relation()

task = Task.new()
task.Project = "3682af82-1898-41dd-a0b3-28ba55c8fc13"  # uuid references a different page

Rich Text

You can now use rich text for text fields using the rich_text module:

from notion_objects import rich_text

class Task(Page):
    title = TitleText()
    description = RichTextProperty()
    description_plain = Text("description")  # can be used to access the plain text easily

task = Task.new()
task.description = rich_text.RichText("my description", bold=True, color="red")

# or set a list of you have multiple text items
task.description = [
    rich_text.RichText("Here is a link: "),
    rich_text.RichText("example.com", "http://example.com"),
]

# you can also access the plain text through proxy attributes
assert task.description_plain == "Here is a link: example.com"

Setting object IDs

Some times you may want to create a new record but then use it to update an existing one. To that end you can now set the id field of a on object:

task = Task.new()
task.id = "3056c466-1920-4291-bc20-74c1f53290dc"

database.update(task)

Changelog

Full Changelog: v0.5.0...v0.6.0