Iterator
iterator
¶
Iterator classes for working with paginated API responses.
MAX_PAGE_SIZE = 100
module-attribute
¶
logger = logging.getLogger(__name__)
module-attribute
¶
BlockList
¶
A list of Block objects returned by the Notion API.
block: Any = Field(default_factory=dict)
class-attribute
instance-attribute
¶
DatabaseList
¶
A list of Database objects returned by the Notion API.
database: Any = Field(default_factory=dict)
class-attribute
instance-attribute
¶
EndpointIterator(endpoint)
¶
Iterates over results from a paginated API response.
These objects may be reused, however they are not thread safe. For example, after creating the following iterator:
notion = notional.connect(auth=NOTION_TOKEN)
query = EndpointIterator(notion.databases().query)
The iterator may be reused with different database ID's:
for items in query(database_id=first_db):
...
for items in query(database_id=second_db):
...
Objects returned by the iterator may also be converted to a specific type. This is most commonly used to wrap API objects with a higher-level object (such as ORM types).
If a class is provided, it will be constructued for each result returned by this iterator. The constructor must accept a single argument, which is the NotionObject
contained in the ObjectList
.
has_more = None
instance-attribute
¶
next_cursor = None
instance-attribute
¶
page_num = -1
instance-attribute
¶
total_items = -1
instance-attribute
¶
__call__(**kwargs)
¶
Return a generator for this endpoint using the given parameters.
as_list(**kwargs)
¶
Collect all items from the endpoint as a list.
ObjectList
¶
A paginated list of objects returned by the Notion API.
More details in the Notion API.
PageList
¶
A list of Page objects returned by the Notion API.
page: Any = Field(default_factory=dict)
class-attribute
instance-attribute
¶
PageOrDatabaseList
¶
A list of Page or Database objects returned by the Notion API.
page_or_database: Any = Field(default_factory=dict)
class-attribute
instance-attribute
¶
PropertyItemList
¶
A paginated list of property items returned by the Notion API.
Property item lists contain one or more pages of basic property items. These types do not typically match the schema for corresponding property values.
property_item: _NestedData = _NestedData()
class-attribute
instance-attribute
¶
UserList
¶
A list of User objects returned by the Notion API.
user: Any = Field(default_factory=dict)
class-attribute
instance-attribute
¶
convert_to_notion_obj(obj: dict[str, Any]) -> Block | Page | Database | PropertyItem | User | GenericObject
¶
Convert a dictionary to the corresponding subtype of Notion Object.
Used in the ObjectList below the convert the results from the Notion API.