SDKs overview

The Notion API provides programmatic access to Notion workspaces, allowing developers to interact with pages, databases, and blocks. To simplify integration, Notion offers official Software Development Kits (SDKs) for popular programming languages. These SDKs abstract away the complexities of HTTP requests, authentication, and error handling, enabling developers to focus on building application logic rather than low-level API interactions. The official Notion API documentation provides a complete overview of available endpoints and data structures for building integrations.

SDKs typically include client libraries that map API endpoints to language-specific methods, data models for request and response bodies, and utilities for authentication and pagination. Using an SDK can reduce development time and improve code maintainability by providing a consistent interface to the API. For example, the official JavaScript SDK handles token management and request serialization, as detailed in the Notion getting started guide.

In addition to official offerings, the Notion developer community has contributed various third-party libraries and tools. These community-driven projects can extend functionality, provide support for other programming languages, or offer specialized wrappers for specific use cases. Developers can explore these options to find solutions that best fit their project requirements, alongside the official Notion integration guides.

Official SDKs by language

Notion provides official SDKs for two primary programming languages, offering a streamlined development experience. These SDKs are maintained by Notion and are the recommended approach for interacting with the Notion API in their respective ecosystems. Each SDK is designed to align with the language's conventions and best practices.

Language Package Name Install Command Example Maturity / Status
JavaScript @notionhq/client npm install @notionhq/client or yarn add @notionhq/client Stable, Production Ready
Python notion-client pip install notion-client Stable, Production Ready

The JavaScript SDK is compatible with both Node.js environments and modern web browsers, supporting asynchronous operations with Promises. Developers can find detailed usage examples and API references for the Notion JavaScript SDK in the official documentation. The Python SDK leverages standard Python libraries and object-oriented principles, making it suitable for backend applications, data scripts, and automation tasks, as described in the Notion Python SDK reference.

Both SDKs encapsulate the Notion API's RESTful interface, managing HTTP requests, JSON serialization/deserialization, and error handling. This means developers do not need to manually construct API URLs or parse raw JSON responses when using these libraries. Instead, they can call methods that correspond directly to Notion API actions, such as client.pages.create() or client.databases.query().

Installation

Installation of the official Notion SDKs follows standard package management practices for their respective language ecosystems. Prior to installation, ensure you have the appropriate package manager (npm/yarn for JavaScript, pip for Python) configured in your development environment. The Notion integration guide provides initial setup steps.

JavaScript SDK

To install the official JavaScript SDK for Notion, open your terminal or command prompt and run one of the following commands:

npm install @notionhq/client

Or, if you prefer using Yarn:

yarn add @notionhq/client

This command downloads the @notionhq/client package and its dependencies, making them available in your project. It's recommended to install these within a project directory where you have a package.json file to manage dependencies.

Python SDK

For Python projects, the official SDK can be installed using pip, Python's package installer:

pip install notion-client

This command fetches the notion-client package from the Python Package Index (PyPI) and installs it into your Python environment. It is generally good practice to install Python packages within a Python virtual environment to isolate project dependencies.

Quickstart example

This quickstart example demonstrates how to use the official Notion JavaScript SDK to retrieve a Notion page. Before running this code, you will need to create an integration in Notion, obtain an API token, and share a page with your integration. Instructions for this setup are available in the Notion API getting started documentation.

Prerequisites

  • Node.js installed
  • Notion integration token (NOTION_API_KEY)
  • A Notion page ID (PAGE_ID)

JavaScript Quickstart Code

import { Client } from "@notionhq/client";

// Initialize the Notion client
const notion = new Client({ auth: process.env.NOTION_API_KEY });

// Replace with the ID of the page you want to retrieve
const pageId = "YOUR_PAGE_ID";

async function getPage() {
  try {
    const page = await notion.pages.retrieve({ page_id: pageId });
    console.log("Page title:", page.properties.title.title[0].plain_text);
    console.log("Page properties:", JSON.stringify(page.properties, null, 2));
  } catch (error) {
    console.error("Error retrieving page:", error.body || error);
  }
}

getPage();

Python Quickstart Code

This example demonstrates retrieving a page using the Python SDK. Ensure you have installed notion-client and set your NOTION_API_KEY and PAGE_ID environment variables or replace them directly in the script.

Prerequisites

  • Python 3.7+ installed
  • Notion integration token (NOTION_API_KEY)
  • A Notion page ID (PAGE_ID)
import os
from notion_client import Client

# Initialize the Notion client
notion = Client(auth=os.environ["NOTION_API_KEY"])

# Replace with the ID of the page you want to retrieve
page_id = "YOUR_PAGE_ID"

async def get_page():
    try:
        page = await notion.pages.retrieve(page_id=page_id)
        # Accessing title property might vary based on your page's setup
        # This is a common pattern for pages created via API with a 'title' property
        title_property = page.get("properties", {}).get("title", {}).get("title")
        if title_property and len(title_property) > 0:
            print(f"Page title: {title_property[0].get('plain_text')}")
        else:
            print("Could not find a title property for this page.")
        print(f"Page properties: {page.get('properties')}")
    except Exception as error:
        print(f"Error retrieving page: {error}")

import asyncio
asyncio.run(get_page())

To run these examples, save the code to a file (e.g., get_notion_page.js or get_notion_page.py), ensure your NOTION_API_KEY and PAGE_ID are correctly set, and then execute it from your terminal using node get_notion_page.js or python get_notion_page.py.

Community libraries

While Notion provides official SDKs for JavaScript and Python, the developer community has developed additional libraries and tools to support other languages or offer specialized functionalities. These community-maintained projects can provide valuable alternatives or complements to the official SDKs, particularly for developers working in environments not directly supported by Notion's official offerings. Developers can often find these projects on platforms like GitHub, npm, or PyPI, by searching for "Notion API client" or "Notion SDK" in their preferred language.

Examples of community-driven efforts often include:

  • Clients for other languages: Developers have created Notion API clients in languages such as Go, Ruby, PHP, Java, and TypeScript (beyond the official JavaScript client's type definitions). These clients aim to provide a native-feeling experience for developers using those specific tech stacks.
  • Framework-specific integrations: Some community libraries offer integrations tailored for popular web frameworks, simplifying common tasks within environments like React, Vue, Django, or Flask.
  • CLI tools: Command-Line Interface (CLI) tools built by the community allow for quick interactions with the Notion API directly from the terminal, useful for scripting or administrative tasks.
  • No-code/Low-code connectors: Beyond traditional code libraries, the community contributes to connectors and plugins for no-code and low-code platforms, enabling broader access to Notion API functionality without extensive programming.

When considering a community library, it's important to evaluate its maintenance status, community support, and alignment with the latest Notion API versions. Checking the project's repository for recent commits, open issues, and documentation quality is advisable. For instance, a well-maintained community library will often track updates to the Notion API versioning policy to ensure compatibility.

Developers should also be aware that community libraries do not carry the same level of official support or guarantees as the SDKs directly provided by Notion. However, many are actively maintained and widely used, offering robust solutions for diverse development needs. Searching on platforms like GitHub for 'notion api client {language}' can help identify popular and well-regarded community projects, as discussed in various developer community forums.