Skip to main content

Notion SDK for Python

A simple and easy to use Python client for the Notion API

PyPI version License Downloads Code style: black

Notion SDK is a fully typed Python library to use the Notion API. It supports asyncio. It uses the great httpx as an HTTP client and pydantic for data validation and typing. This client is meant to be a Python version of the reference JavaScript SDK, so usage should be pretty similar between both.

Installation

$ pip install notion-sdk

Usage

Import and initialize a client using an integration token or an OAuth access token.

from notion import NotionClient

notion = NotionClient(auth="YOUR_ACCESS_TOKEN")

def fetch_databases() -> None:
    response = notion.databases.list()
    for database in response.results:
        print(database.title)

if __name__ == "__main__":
    fetch_databases()

More example are available in the examples folder.

Async Usage

This library supports asynchronous calls to Notion API.

Each method returns a Coroutine that have to be awaited to retreive the typed response.

The same methods are available for sync or async but you have to use the NotionAsyncClient like in the following example:

import asyncio

from notion import NotionAsyncClient

notion = NotionAsyncClient(auth="YOUR_ACCESS_TOKEN")

async def fetch_databases() -> None:
    response = await notion.databases.list()
    for database in response.results:
        print(database.title)

if __name__ == "__main__":
    asyncio.run(fetch_databases())

Clients options

NotionClient and NotionAsyncClient support the following options on initialization. These options are all keys in the single constructor parameter.

Option Default value Type Description
auth None string Bearer token for authentication. If left undefined, the auth parameter should be set on each request.
timeout 60 int Number of seconds to wait before emitting a RequestTimeoutError
base_url "https://api.notion.com/v1/" string The root URL for sending API requests. This can be changed to test with a mock server.
user_agent notion-sdk/VERSION (https://github.com/getsyncr/notion-sdk) string A custom user agent send with every request.

Requirements

This package supports the following minimum versions:

  • Python >= 3.7
  • httpx >= 0.15.0
  • pydantic >= 1.7

Earlier versions may still work, but we encourage people building new applications to upgrade to the current stable.

License

Distributed under the Apache License. See LICENSE for more information.

Metadata

Release files for notion-sdk 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for notion-sdk 0.7.0
File Size Uploaded
notion-sdk-0.7.0.tar.gz 16.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for notion-sdk 0.7.0
File Interpreter ABI Platform
notion_sdk-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 34.2 kB

Release files / notion-sdk-0.7.0.tar.gz

Download URL notion-sdk-0.7.0.tar.gz
Size 16.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2c5a76aea4e607b93d9b403aae08ad1b9a11525d766ebea41105ba1478fcefff
BLAKE2b-256 checksum
How to use checksums
3327113032de6262cd59d7bcc6e40c7ec1b1add1353c484754a016341f375114
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.7 CPython/3.9.5 Darwin/20.5.0

Release files / notion_sdk-0.7.0-py3-none-any.whl

Download URL notion_sdk-0.7.0-py3-none-any.whl
Size 17.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
df66baf53739235b3725ca202f8e593e18d6d09c9ece98b562f3b65b06d59e6d
BLAKE2b-256 checksum
How to use checksums
6eab1c8a19134bfed2af7d55e18e020af8d0c9c0033ceb89c715b69456a2709e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.7 CPython/3.9.5 Darwin/20.5.0

Release history Release notifications | RSS feed

This release

0.7.0 This release

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page