Skip to content

Iterator

iterator

Iterator classes for working with paginated API responses.

MAX_PAGE_SIZE = 100 module-attribute

T = TypeVar('T', bound=NotionObject) module-attribute

BlockList

A list of Block objects returned by the Notion API.

block: TypeData instance-attribute

TypeData

CommentList

A list of Comment objects returned by the Notion API.

comment: TypeData instance-attribute

TypeData

EndpointIterator(endpoint: Callable[..., Any | Awaitable[Any]], model_validate: Callable[[Any], NotionObject] = ObjectList.model_validate)

Functor to iterate over results from a potentially paginated API response.

In most cases notion_obj should be ObjectList. For some endpoints, like PropertiesEndpoint, and endpoint returns a list of property items or s single property item. In this case, model_validate should be TypeAdapter(PropertyItemList | PropertyItem).validate_python or whatever you expect to be returned.

has_more: bool | None = None class-attribute instance-attribute

next_cursor: str | None = None class-attribute instance-attribute

page_num: int = -1 class-attribute instance-attribute

total_items: int = -1 class-attribute instance-attribute

__call__(**kwargs: Any) -> Iterator[T]

Return a generator for this endpoint using the given parameters.

ObjectList

A paginated list of objects returned by the Notion API.

More details in the Notion API.

has_more: bool = False class-attribute instance-attribute

next_cursor: str | None = None class-attribute instance-attribute

results: list[Annotated[NotionObject, BeforeValidator(convert_to_notion_obj)]] = Field(default_factory=list) class-attribute instance-attribute

PageOrDatabaseList

A list of Page or Database objects returned by the Notion API.

page_or_database: TypeData instance-attribute

TypeData

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: TypeData instance-attribute

TypeData

id: str instance-attribute
model_config = ConfigDict(extra='allow') class-attribute instance-attribute
next_url: str | None instance-attribute
type: str instance-attribute

UserList

A list of User objects returned by the Notion API.

user: TypeData instance-attribute

TypeData

convert_to_notion_obj(data: 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.