Notion API Client (Unofficial)
This is an unofficial Python API client for Notion.so, providing an object-oriented interface to interact with Notion data. It's currently at version 0.1.0 (released March 2026) and aims to adapt to Notion's internal API changes. As an unofficial client, its release cadence is driven by necessary adaptations to Notion's evolving undocumented API.
Warnings
- breaking This library relies on Notion's unofficial/internal API, which is subject to change without notice. The v0.1.0 release (March 2026) introduced breaking changes to adapt to Notion's latest internal API (v3) modifications, including migration from `getRecordValues` to `syncRecordValues`, updated `queryCollection` aggregation, `getBacklinksForBlock` to `getBacklinksForBlockInitial`, and `search` endpoint sort parameter format.
- gotcha Authentication uses `token_v2`, obtained from Notion.so browser cookies. This token is session-specific, highly fragile, and prone to expiration or invalidation without warning, leading to `HTTPError` or `Unauthorized` errors.
- gotcha There is significant confusion between this unofficial `notion` library (`jamalex/notion-py` on GitHub) and the official Python SDK, `notion-sdk-py`. The two libraries are not fully compatible and use different authentication methods and API patterns.
- gotcha When using `client.get_block()`, ensure the `token_v2` has explicit read/write permissions to the specific Notion page or database you are trying to access. Lack of permissions often results in `object_not_found` or `restricted_resource` errors, even with a valid token.
Install
-
pip install notion
Imports
- NotionClient
from notion.client import NotionClient
Quickstart
import os
from notion.client import NotionClient
# IMPORTANT: This library uses the internal Notion API and requires a token_v2 from browser cookies.
# It is unofficial and prone to breakage. For official API access, use 'notion-sdk-py'.
# Replace 'NOTION_TOKEN_V2' with your actual token_v2 from Notion.so browser cookies.
# This token is session-specific and can expire.
token_v2 = os.environ.get('NOTION_TOKEN_V2', '')
if not token_v2:
print("Error: NOTION_TOKEN_V2 environment variable not set. Please provide your token_v2 cookie value.")
else:
try:
client = NotionClient(token_v2=token_v2)
# Replace with the URL or ID of a Notion page you have access to
page_url = "https://www.notion.so/myorg/Test-c0d20a71c0944985ae96e661ccc99821" # Example URL
# Ensure the client's token has access to the page
page = client.get_block(page_url)
print(f"Successfully accessed page: {page.title}")
# Example: Update the page title
# page.title = "New Title from Python!"
# print(f"Page title updated to: {page.title}")
# Example: List children blocks (if any)
# for child in page.children:
# print(f" - Child block: {child.title}")
except Exception as e:
print(f"An error occurred: {e}")
print("Common issues: invalid token_v2, page not shared with the token's user, or Notion's internal API changed.")