Help for retrieving only some properties of a whole database #100
Unanswered
thomashirtz
asked this question in
Q&A
Replies: 1 comment
-
This post can be close, I ended up querying the whole db and filtering it afterwards. I do not think a better way exist right now. def get_publication_key_list_from_database(
token: str,
database_id: str,
page_size: int = 100,
) -> List[str]:
notion = Client(auth=token)
results = []
query = notion.databases.query(database_id=database_id, page_size=page_size)
results.extend(query['results'])
while query['next_cursor']:
query = notion.databases.query(database_id=database_id, start_cursor=query['next_cursor'], page_size=page_size)
results.extend(query['results'])
key_list = []
for result in results:
try:
key_list.append(result['properties']['Filename']['rich_text'][0]['plain_text'])
except IndexError:
pass
return key_list |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am trying to transfer the backend of my repository from notion-py to notion-sdk-py. However I struggle to do something.
I have a large database, and I want to only retrieve one or two columns:
for example, I would like to get all the "Filename" properties from a certain database. However my databases are quite large, so I would like to filter which information to get. Does someone know how to do this ?
Current working code: (but does not deliver results I want)
My database is too large to do the simple
notion.databases.query
and filter afterwards. And I try to search on the database query and the search method (Maybe I could have done database=database_id and property=property_needed, but it seems not be possible and not mentioned in the API guide). I can't find such functionality on the documentationBeta Was this translation helpful? Give feedback.
All reactions