SDKs overview

Notion provides a suite of official SDKs designed to simplify interaction with its public API. These SDKs abstract much of the complexity of making direct HTTP requests, handling authentication, data serialization, and error management. By using an SDK, developers can integrate Notion's features—such as managing databases, creating and updating pages, and interacting with blocks—directly into their applications using familiar language constructs. The official Notion API documentation provides comprehensive guides for getting started with these tools, including authentication methods and example use cases for various endpoints.

The Notion API itself is a RESTful interface, allowing for standard HTTP methods (GET, POST, PATCH, DELETE) to interact with resources like databases, pages, and blocks. The SDKs wrap these underlying API calls, providing idiomatic interfaces for each supported language. This approach aims to accelerate development and reduce the boilerplate code typically associated with direct API consumption. For instance, creating a new page in a database or retrieving specific block content can be achieved with a few lines of code using an SDK, rather than constructing full HTTP requests manually. For detailed API specifications and available endpoints, developers can consult the Notion API reference documentation.

Official SDKs by language

Notion maintains official SDKs for several popular programming languages, ensuring direct support and ongoing updates from the Notion development team. These SDKs are published as open-source packages and are available through standard package managers for each language. Each SDK is designed to reflect the nuances of its respective language while providing a consistent interface to the Notion API. This consistency helps developers who work across multiple languages to adapt quickly to the Notion API's structure.

The table below outlines the officially supported SDKs, including their respective package names and typical installation commands:

Language Package Name Installation Command Maturity
JavaScript @notionhq/client npm install @notionhq/client or yarn add @notionhq/client Stable
Python notion-client pip install notion-client Stable
Go github.com/jomei/notionapi go get github.com/jomei/notionapi Stable
Ruby notion_api gem install notion_api Stable

These SDKs provide type definitions where applicable (e.g., TypeScript for JavaScript, type hints for Python), which aids in code completion and error checking during development. The official SDKs are the recommended approach for building integrations due to their direct support and alignment with the latest API versions. Developers can find specific setup instructions and usage examples for each language client within the Notion developer documentation.

Installation

Installing Notion's official SDKs involves using the standard package manager for your chosen programming language. The process is typically straightforward and requires a single command to add the library to your project's dependencies.

JavaScript (Node.js/TypeScript)

For JavaScript and TypeScript projects, the official SDK is available via npm or Yarn. This client is fully typed, offering a robust development experience for modern web applications and server-side Node.js environments.

# Using npm
npm install @notionhq/client

# Using Yarn
yarn add @notionhq/client

Python

Python developers can install the notion-client package using pip, Python's package installer. This client supports Python 3.7+ and integrates well into various Python frameworks and scripts.

pip install notion-client

Go

The Go SDK for Notion is installed using the go get command. After installation, it can be imported into Go projects to interact with the Notion API using Go's strong typing and concurrency features.

go get github.com/jomei/notionapi

Ruby

Ruby applications can integrate with Notion using the notion_api gem, installed via Bundler or the gem install command. This allows Ruby developers to build integrations within Rails applications or standalone scripts.

gem install notion_api

After installation, the SDK can be imported into your project, and an API client can be initialized using an integration token. This token, which authenticates your application with Notion, should be kept secure and managed as an environment variable or through a secrets management service. For guidance on obtaining an integration token and connecting to Notion, refer to the Notion integration setup guide.

Quickstart example

This quickstart example demonstrates how to use the Notion JavaScript SDK to retrieve a database and then create a new page within it. This common pattern illustrates authentication, querying, and data manipulation through the SDK.

Prerequisites

  • Node.js installed
  • Notion integration token (NOTION_API_KEY)
  • A Notion database ID (NOTION_DATABASE_ID)

JavaScript Example: Retrieve Database and Create Page

First, ensure you have installed the JavaScript SDK:

npm install @notionhq/client dotenv

Create a .env file in your project root with your Notion API key and database ID:

NOTION_API_KEY="secret_YOUR_NOTION_API_KEY"
NOTION_DATABASE_ID="YOUR_DATABASE_ID"

Then, create a JavaScript file (e.g., app.js) with the following content:

require('dotenv').config();
const { Client } = require('@notionhq/client');

const notion = new Client({ auth: process.env.NOTION_API_KEY });
const databaseId = process.env.NOTION_DATABASE_ID;

async function main() {
  try {
    // 1. Retrieve a database
    console.log('Retrieving database...');
    const database = await notion.databases.retrieve({
      database_id: databaseId,
    });
    console.log('Database retrieved:', database.title[0].plain_text);

    // 2. Create a new page in the database
    console.log('Creating a new page...');
    const newPage = await notion.pages.create({
      parent: { database_id: databaseId },
      properties: {
        'Name': {
          title: [
            {
              text: {
                content: 'New Task from SDK',
              },
            },
          ],
        },
        'Status': {
          select: {
            name: 'To Do',
          },
        },
      },
      children: [
        {
          object: 'block',
          type: 'paragraph',
          paragraph: {
            rich_text: [
              {
                type: 'text',
                text: {
                  content: 'This page was created programmatically using the Notion SDK.',
                },
              },
            ],
          },
        },
      ],
    });
    console.log('New page created:', newPage.url);

  } catch (error) {
    console.error('Error:', error.body || error);
  }
}

main();

Run the script:

node app.js

This script will first fetch details about the specified database and then add a new page titled "New Task from SDK" with a "To Do" status and some initial paragraph content. This demonstrates the basic flow of authenticating, reading data, and writing data using the Notion SDK. Developers can expand upon this by exploring other methods for interacting with blocks, users, and comments, as detailed in the Notion API page creation documentation.

Community libraries

While Notion provides official SDKs, the developer community has also contributed a range of libraries and tools that extend functionality or offer alternative interfaces to the Notion API. These community-driven projects can sometimes provide specialized features, support for less common languages, or different architectural approaches that might suit specific project requirements. It is important to note that community libraries may not receive the same level of ongoing support or official compatibility guarantees as the first-party SDKs.

Examples of community contributions include:

  • notion-py: An unofficial Python client that predates the official SDK and is still used in some projects. While the official notion-client is now the recommended choice, notion-py served as an important community effort.
  • notion-sdk-js-beta: Early versions or specialized forks of the JavaScript SDK that might explore experimental features or provide specific utility functions not yet integrated into the official client.
  • Various language wrappers: Developers have created wrappers for languages not officially supported, such as C#, PHP, or Rust, often found on platforms like GitHub. These projects typically rely on direct HTTP calls to the Notion API but encapsulate them in a language-specific way.
  • CLI tools: Command-line interface tools built by the community to interact with Notion from the terminal, useful for scripting and automation without writing full applications.
  • Data synchronization tools: Open-source projects designed to synchronize Notion content with other platforms or databases, often leveraging the Notion API for bulk data operations.

When considering a community library, developers should evaluate its active maintenance, community support, and alignment with the current Notion API version. Consulting the project's documentation, GitHub repository, and recent commit history can provide insights into its reliability and suitability for long-term use. For instance, developers seeking to integrate Notion with other productivity tools might explore community projects that bridge these platforms, as discussed in broader developer discussions around Google Workspace integrations, which often highlight the role of third-party libraries in extending core application functionality.