notion-objects

A Python library that makes it easy to work with objects in a notion database. 🚧 under development!

APACHE-2.0 License

Downloads
543
Stars
22
Committers
1

Bot releases are hidden (Show)

notion-objects - notion-objects 0.5.0 Latest Release

Published by thrau about 1 year ago

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
notion-objects - v0.4.0

Published by thrau about 2 years ago

Summary

  • Database(...).title will now return the name of the database
  • You can now do basic updating of pages. If you use the database without type mapping, you currently use subscripts to set the property values:
      db = Database(database_id, Client(auth=notion_token))
      page = db.find_by_id("b59fec7c9a4b43b1b169bd10aa843053")
      page['MyAttribute'] = "foo"
      db.update(page)
    
    if you use custom models, you need at least an id field + use attribute setters (page.MyAttribute = "foo")

What's changed

Full Changelog: https://github.com/thrau/notion-objects/compare/v0.3.0...v0.4.0