Helpers
Utility functions for notion-sdk-py.
async_collect_data_source_templates(function, **kwargs)
async
Collect asynchronously all templates from a data source into a list.
Example:
templates = await async_collect_data_source_templates(
async_client.data_sources.list_templates,
data_source_id=data_source_id,
)
# Do something with templates.
Source code in notion_client/helpers.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 | |
async_collect_paginated_api(function, **kwargs)
async
Collect asynchronously all the results of paginating an API into a list.
Source code in notion_client/helpers.py
85 86 87 88 89 | |
async_iterate_data_source_templates(function, **kwargs)
async
Return an async iterator over templates from a data source.
Example:
async for template in async_iterate_data_source_templates(
async_client.data_sources.list_templates,
data_source_id=data_source_id,
):
print(template["name"], template["is_default"])
Source code in notion_client/helpers.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | |
async_iterate_paginated_api(function, **kwargs)
async
Return an async iterator over the results of any paginated Notion API.
Source code in notion_client/helpers.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
collect_data_source_templates(function, **kwargs)
Collect all templates from a data source into a list.
Example:
templates = collect_data_source_templates(
client.data_sources.list_templates,
data_source_id=data_source_id,
)
# Do something with templates.
Source code in notion_client/helpers.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | |
collect_paginated_api(function, **kwargs)
Collect all the results of paginating an API into a list.
Source code in notion_client/helpers.py
64 65 66 | |
extract_block_id(url_or_id)
Extract a block ID from a Notion URL fragment or validate if it's already a valid ID.
Specifically looks for block IDs in URL fragments (after #).
If no fragment is present, falls back to extract_notion_id behavior.
Returns the extracted UUID in standard format (with hyphens) or None if invalid.
Source code in notion_client/helpers.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
extract_database_id(database_url)
Extract a database ID from a Notion URL or validate if it's already a valid ID.
This is an alias for extract_notion_id for clarity when working with databases.
Returns the extracted UUID in standard format (with hyphens) or None if invalid.
Source code in notion_client/helpers.py
207 208 209 210 211 212 213 214 | |
extract_notion_id(url_or_id)
Extract a Notion ID from a Notion URL or return the input if it's already a valid ID.
Prioritizes path IDs over query parameters to avoid extracting view IDs instead of database IDs.
Returns the extracted UUID in standard format (with hyphens) or None if invalid.
# Database URL with view ID - extracts database ID, not view ID
extract_notion_id('https://notion.so/workspace/DB-abc123def456789012345678901234ab?v=viewid123')
# Returns: 'abc123de-f456-7890-1234-5678901234ab' # database ID
# Already formatted UUID
extract_notion_id('12345678-1234-1234-1234-123456789abc')
# Returns: '12345678-1234-1234-1234-123456789abc'
Source code in notion_client/helpers.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
extract_page_id(page_url)
Extract a page ID from a Notion URL or validate if it's already a valid ID.
This is an alias for extract_notion_id for clarity when working with pages.
Returns the extracted UUID in standard format (with hyphens) or None if invalid.
Source code in notion_client/helpers.py
217 218 219 220 221 222 223 224 | |
get_id(url)
Return the id of the object behind the given URL.
Source code in notion_client/helpers.py
36 37 38 39 40 41 42 43 44 45 | |
get_url(object_id)
Return the URL for the object with the given id.
Source code in notion_client/helpers.py
31 32 33 | |
is_equation_rich_text_item_response(rich_text)
Return True if rich_text is an equation.
Source code in notion_client/helpers.py
129 130 131 | |
is_full_block(response)
Return True if response is a full block.
Source code in notion_client/helpers.py
92 93 94 | |
is_full_comment(response)
Return True if response is a full comment.
Source code in notion_client/helpers.py
119 120 121 | |
is_full_database(response)
Return True if response is a full database.
Source code in notion_client/helpers.py
102 103 104 | |
is_full_page(response)
Return True if response is a full page.
Source code in notion_client/helpers.py
97 98 99 | |
is_full_page_or_database(response)
Return True if response is a full database or a full page.
Source code in notion_client/helpers.py
107 108 109 110 111 | |
is_full_user(response)
Return True if response is a full user.
Source code in notion_client/helpers.py
114 115 116 | |
is_mention_rich_text_item_response(rich_text)
Return True if rich_text is a mention.
Source code in notion_client/helpers.py
134 135 136 | |
is_text_rich_text_item_response(rich_text)
Return True if rich_text is a text.
Source code in notion_client/helpers.py
124 125 126 | |
iterate_data_source_templates(function, **kwargs)
Return an iterator over templates from a data source.
Example:
for template in iterate_data_source_templates(
client.data_sources.list_templates,
data_source_id=data_source_id,
):
print(template["name"], template["is_default"])
Source code in notion_client/helpers.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
iterate_paginated_api(function, **kwargs)
Return an iterator over the results of any paginated Notion API.
Source code in notion_client/helpers.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 | |
pick(base, *keys)
Return a dict composed of key value pairs for keys passed as args.
Source code in notion_client/helpers.py
18 19 20 21 22 23 24 25 26 27 28 | |