Skip to main content

NotionAI Python SDK

The NotionAI Python SDK is a wrapper for the NotionAI APIs with Python bindings, simplifying integration of NotionAI solutions into your projects.

Features

  • Full APIs from Notion AI
  • Support stream response

API

All NotionAI functionalities are supported. Check out the notionai.py file to see all the available APIs.

Basic API Shortcuts

APIs like blog_post, help_me_write, help_me_edit, and summarize are shortcuts for the basic APIs.

Advanced APIs

We also support advanced APIs that allow you to dispatch by parameters:

  1. writing_with_topic
    Writing for special topic
    Args:
        topic (TopicEnum): the special topic
        prompt (str): prompt for writing
    Example:
        ao = NotionAI(token)
        ai.writing_with_topic(TopicEnum.blog_post, "Please help to introduce Notion")
    
  2. writing_with_prompt
    Writing with special prompt, like summarize, explain_this, improve_writing
    
    Args:
        prompt_type (PromptTypeEnum): special prompt
        context (str): the context for your writing
    
    Example:
        ai = NotionAI(token)
        ai.writing_with_prompt(PromptTypeEnum.summarize, "I am a student")
    
  3. translate
    Translate the text
    Args:
        language (TranslateLanguageEnum): target language
        context (str): context to translate
    
    Example:
        ai = NotionAI(token)
        ai.translate(TranslateLanguageEnum.Chinese, "I am a student")
    
  4. change_tone
     Change the tone of your context
     Args:
         context (str): context to change
         tone (ToneEnum): target tone
    
     Returns:
         str: Response from NotionAI
     Example:
         ai = NotionAI(token)
         ai.change_tone("I am a student", ToneEnum.professional)
    

Usage

Install

pip install --upgrade notionai-py

Get Notion Token and Workspace ID

To use the NotionAI Python SDK, you need to obtain a Notion token. You can do this by following these steps:

  1. Open Chrome or Firefox DevTools
  2. Find Cookies and copy the value for token_v2
  3. Find the spaceId of your Notion workspace
  • get notion token Get Notion Token
  • get notion workspace id Get Notion Workspace ID

Note: Now can get Notion space id using api

import os
from notionai import NotionAI
TOKEN = os.getenv("NOTION_TOKEN")

spaces = NotionAI.get_spaces(TOKEN)
print(spaces)
# the result will looks like
# [{'id': 'xxxxx', 'name': 'xxxxx'}]

Note2: Now supports custom api proxy links

import os
from notionai import NotionAI
TOKEN = os.getenv("NOTION_TOKEN")
SPACE_ID = os.getenv("NOTION_SPACE_ID")
API_URL = "https://xxx.xxx.xxx"  # this is your custom proxy links

ai = NotionAI(TOKEN, SPACE_ID, api_url=API_URL)
res = ai.blog_post("write a blog about the meaning of life")
print(res)

Examples

Check out the examples directory for usage examples.

  1. Basic
import os
from notionai import NotionAI

TOKEN = os.getenv("NOTION_TOKEN")
SPACE_ID = os.getenv("NOTION_SPACE_ID")

def main():
    ai = NotionAI(TOKEN, SPACE_ID)
    res = ai.blog_post("write a blog about the meaning of life")
    print(res)

if __name__ == "__main__":
    main()
  1. Stream API
import os
import sys
from notionai import NotionAI

TOKEN = os.getenv("NOTION_TOKEN")
SPACE_ID = os.getenv("NOTION_SPACE_ID")

def main():
    ai = NotionAIStream(TOKEN, SPACE_ID)
    res = ai.blog_post("write a blog about the meaning of life")
    for item in res:
        sys.stdout.write(item)

if __name__ == "__main__":
    main()
  1. WebUI

Check out the webui directory for instructions on how to use the NotionAI Python SDK with a web user interface.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

notionai-py-0.1.6.tar.gz (728.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

notionai_py-0.1.6-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file notionai-py-0.1.6.tar.gz.

File metadata

  • Download URL: notionai-py-0.1.6.tar.gz
  • Upload date:
  • Size: 728.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for notionai-py-0.1.6.tar.gz
Algorithm Hash digest
SHA256 74247129da3ca8dc52077a09af5fd3c129a7e607da34d9ef7cde1ec90617b570
MD5 9edf366ee5c9d68d41a3553cbf148c22
BLAKE2b-256 4b98194f156a9062154bd99c3d34d68e813f8c2e4b4ede543dd58ebdaff880f2

See more details on using hashes here.

File details

Details for the file notionai_py-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: notionai_py-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for notionai_py-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 c43656302f70095e4ec52745ac4e9e102c0cdc21633ddb539302e901619a0358
MD5 14f7457686a3c153d867f96c4804dd7b
BLAKE2b-256 aec562e29a8fbe884a5dc02a08652324b20f9ac1ddf576cdd325792af92313ed

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page