minwook-shin / notion-database

Python bindings for Notion Database API
https://pypi.org/project/notion-database/
GNU Lesser General Public License v3.0
137 stars 12 forks source link

How to get all pages from a database #2

Closed theotheo closed 3 years ago

theotheo commented 3 years ago

Hi, there!

I see how I can fetch single page, but I don't figure out how to get all pages from database. Is there a method for this?

minwook-shin commented 3 years ago

thanks you! implemented it now! find_all_page()

Install notion-database==20210513.7, and check the changed code in README.

example :

import os
import pprint

from notion_database.database import Database

NOTION_KEY = os.getenv('NOTION_KEY')

# List Database
D = Database(integrations_token=NOTION_KEY)
D.list_databases(page_size=100)

for i in D.result["results"]:
    database_id = i["id"]

    # Finding all pages in a database
    D.find_all_page(database_id=database_id)
    pprint.pprint(D.result)
theotheo commented 3 years ago

Excellent! Thank you!

BigBerny commented 2 years ago

There's a limit for 100 pages though, afterwards you need pagination. Is this supported?

minwook-shin commented 2 years ago

There's a limit for 100 pages though, afterwards you need pagination. Is this supported?

If support as Notion official API, pagination feature will be added soon.

BigBerny commented 2 years ago

It is supported by the official API 👍️

minwook-shin commented 2 years ago

@BigBerny

20220628.1 version has been released! implemented pagination feature. (and more...) https://github.com/minwook-shin/notion-database/blob/main/CHANGELOG.md#2022-06-281-2022-08-01

pip install notion-database==20220628.1
# Finding all pages in a database
D.find_all_page(database_id=database_id, page_size=100)
if D.result["has_more"]:
    D.find_all_page(database_id=database_id, start_cursor=D.result["next_cursor"])
BigBerny commented 2 years ago

Awesome, thanks!