Notion API Client (Unofficial)

0.1.0 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

Initializes the NotionClient using a `token_v2` (obtained from browser cookies, not an official integration token) and retrieves a Notion page. This example demonstrates basic page access and highlights the authentication method.

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.")

view raw JSON →