Skip to main content

Unoffical Notion AI API

Project description

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.

Project details


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.5.tar.gz (727.9 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.5-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for notionai-py-0.1.5.tar.gz
Algorithm Hash digest
SHA256 5e9c1fa5213f3095a0f1cd97d49c928ab6521d7efe2a3e6aac0fd3d598522fb2
MD5 b39cfd5e49b4d5859038d14a8e42a8b6
BLAKE2b-256 552e281f7e911ddc4f66f0846d16f583268496e4c73212a553d4f534c4e5d750

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for notionai_py-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c10aeac060389d1e632cdda90b3ce4d539e360842877463234069ab60602b73d
MD5 25acf2eecc995f8284e908ea5e57ef25
BLAKE2b-256 1a318ca0f846d2e10b2d39393d1c9cffb239cbb05e8995cd661277a564384d57

See more details on using hashes here.

Supported by

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