A Python library that makes it easy to work with objects in a notion database. 🚧 under development!
APACHE-2.0 License
Bot releases are hidden (Show)
This release brings update and create operations for notion database pages. Previously, notion-objects supported only read-only operations.
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.
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
Published by thrau about 2 years ago
Database(...).title
will now return the name of the database 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"
)Full Changelog: https://github.com/thrau/notion-objects/compare/v0.3.0...v0.4.0