Notion-objects

Latest version: v0.6.2

Safety actively analyzes 622389 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

0.6.0

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:

python
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`.
python
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:
python
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.

python
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:

python
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:

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

database.update(task)


Changelog

**Full Changelog**: https://github.com/thrau/notion-objects/compare/v0.5.0...v0.6.0

0.5.0

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.

python
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.

python
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

0.4.0

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:
python
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

Links

Releases

Has known vulnerabilities

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.