Skip to content

notion-objects 0.5.0

Compare
Choose a tag to compare
@thrau thrau released this 14 Oct 14:38
· 13 commits to main since this release

This release brings update and create operations for notion database pages. Previously, notion-objects supported only read-only operations.

Updating records

You can update database records by simply calling attributes with normal python assignments.
The data mapper will map the types correctly to Notion's internal format.
You can then call Database.update(...) to run an update API call.
notion-objects keeps track of all the changes that were made to the object, and only sends the changes.

class Task(NotionObject):
    name = TitlePlainText("Name")
    status = Status("Status")
    closed_at = DateTime("Closed at")
    assigned_to = Person("Assigned to")

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

task = database.find_by_id("...")
task.status = "Done"
task.closed_at = datetime.utcnow()
database.update(task)

Note not all properties can be set yet.

Creating records

Similarly, you can also create new pages.
You can use NotionObject.new() on any subclass to create new unmanaged instances of that type.
Then, call Database.create(...) to create a new item in the database.

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

task = Task.new()
task.task = "My New Task"
task.status = "In progress"
task.assigned_to = "6aa4d3cd-3928-4f61-9072-f74a3ebfc3ca"

task = database.create(task)
print(task.id)  # it now has a database id