Python 3 tools for interacting with Notion API

Overview

NotionDB

Python 3 tools for interacting with Notion API:

  • API client

  • Relational database wrapper

Installation

pip install notiondb

API client

from notiondb import NotionApi

api = NotionApi(API_TOKEN)  # Token from Internal Integration

# Databases
databases, next_cursor = api.get_databases()

api.create_database(parent_id, title, properties)

api.get_database(id)

api.update_database(id, title, properties)

pages, next_cursor = api.query_database(filter, sorts, start_cursor, page_size)

# Pages
pages, next_cursor = api.get_pages(query, start_cursor, page_size)

# Create page in database
api.create_page('database_id', parent_id, title, properties, children, icon, cover)
# Create page in parent page
api.create_page('page_id', parent_id, title, properties, children, icon, cover)

api.get_page(id)

api.update_page(id, properties, archived)

# Get page's block children
blocks, next_cursor = api.get_block_children(id, start_cursor, page_size)

api.append_block_children(id, children)

Wrapper for relational database

Interacting with Notion database as a relational database.

Create database

from notiondb import NotionDatabase
from notiondb.fields import *

properties = [
    TitleField(name='Name'),
    RichTextField(name='Description'),
    CheckboxField(name='In stock'),
    SelectField(name='Food group', options=[
        {
            "name": "🥦Vegetable",
            "color": "green"
        },
        {
            "name": "🍎Fruit",
            "color": "red"
        },
        {
            "name": "💪Protein",
            "color": "yellow"
        }
    ]),
    NumberField(name='Price', format='dollar'),
]

# Create new database
database = NotionDatabase(TOKEN, parent_id=NOTION_PARENT_PAGE_ID, title='Database title', properties=properties)

# Or get existing database
database = NotionDatabase(TOKEN, database_id=DATABASE_ID)

Define document's structure

from notiondb import NotionModel
from notiondb.fields import *


class TestModel(NotionModel):
  
    def __init__(self, database=None, id=None):
        super().__init__(database=database, id=id)

        self.name = TitleField('Name')
        self.description = RichTextField('Description')
        self.in_stock = CheckboxField('In stock')
        self.food_group = SelectField('Food group')
        self.price = NumberField('Price')

Add a row

model = TestModel(database)

model.name.value = 'Name'
model.description.value = 'Description'
model.in_stock.value = True
model.food_group.value = '🥦Vegetable'
model.price.value = 2.33

model.save()

Update a row

# Get a row from id
model = TestModel.from_id(database, row_id)
# Or from data retrieved by API
model = TestModel.from_data(database, data)

model.name.value = 'Name updated'

model.save()

Append block children to page

from notiondb.block import *

children = [
    TableOfContentsBlock(),
    ParagraphBlock('paragraph 1'),
    ParagraphBlock('paragraph 2', link='https://example.com'),
]
model.append_children(children)

Query database

Filter & sorts reference

cursor = TestModel.objects(database).get(filter=filter, sorts=sorts, limit=limit)
for item in cursor:
    # do something

Get row's data

# Get row's block children
children = model.get_children()

# Parse to JSON
data = model.to_json(includes_children=True)

Delete a row

model.delete()

Testing

Create .env file in ./tests

NOTION_TOKEN=
# Parent page id for testing
DEV_PAGE_NOTION_ID=

Run tests

python -m unittest

Owner
Viet Hoang
Viet Hoang
This Instagram app created as a clone of instagram.Developed during Moringa Core.

Instagram This Instagram app created as a clone of instagram.Developed during Moringa Core. AUTHOR By: Nyagah Isaac Description This web-app allows a

Nyagah Isaac 1 Nov 01, 2021
Live Coding - Mensageria na AWS com Amazon SNS e Amazon SQS

Live Coding - Mensageria na AWS com Amazon SNS e Amazon SQS Repositório para o Live Coding do dia 08/12/2021 Serviços utilizados Amazon SNS Amazon SQS

Cassiano Ricardo de Oliveira Peres 3 Mar 01, 2022
Telegram bot to host python bots

Host-Bot Setup the api Upload the flask api on your host #its not important to do #i used it just for simple captcha system + save ids on your host!

Plugin 15 Feb 11, 2022
szrose is an all in one group management bot made for managing your group effectively with some advance security tools & Suit For All Your Needs ❤️

szrose is an all in one group management bot made for managing your group effectively with some advance security tools & Suit For All Your Needs ❤️

szsupunma 93 Jan 07, 2023
Protect Discord server invite link

DiscordOauth2Join Protect discord server invite links! Setup I will not help setting up the discord application, but just python. First, install the r

ZEEE 4 Aug 12, 2021
Python client for Toyota North America service API

toyota-na Python client for Toyota North America service API Install pip install toyota-na[qt] [qt] is required for generating authorization code. Us

Gavin Ni 18 Sep 06, 2022
Tiktok-bot - A tiktok bot with python

Install the requirements pip install selenium pip install pyfiglet==0.7.5 How ca

Ukis 5 Aug 23, 2022
A simple script & container to pull COVID data from covidlive.com.au and post a summary to a slack channel

CovidLive AU Summary Slackbot This bot is a very simple slackbot that pulls data, summarises and posts up to date AU COVID stats to a provided slack c

James 3 Dec 18, 2021
Decrypt PSSE layer of PSM Games (on PC)

psse-decrypt Decrypt PSSE layer of PSM Games (on PC) Works on Unity and PSM games, and meets all requirements of: https://github.com/vita-nuova/bounti

Bluzume 32 Oct 11, 2022
Join & Leave spam for aminoapps using aminoboi

JLspam.py Join & Leave spam for https://aminoapps.com using aminoboi Instalação apt-get update -y apt-get upgrade -y apt-get install git pkg install

Moleey 1 Dec 21, 2021
Convenient script for trading with python.

Convenient script for trading with python.

VladKochetov007 66 Dec 07, 2022
A simple python script for rclone. Use multiple Google Service Accounts and cycle through them.

About GSAclone GSAclone is a simple python script for rclone, written with the purpose of using multiple Google service accounts on Google Drive and "

Shiro39 6 Feb 25, 2022
rewise is an unofficial wrapper for google search's auto-complete feature

rewise is an unofficial wrapper for google search's auto-complete feature

Somdev Sangwan 71 Jul 19, 2022
CyberTKR - CyberTK-API

CyberTKR - CyberTK-API

TKR 2 Apr 08, 2022
The Sue Gray Alert System was a 5 minute project that just beeps every time a new article is updated or published on Gov.UK's news pages.

The Sue Gray Alert System was a 5 minute project that just beeps every time a new article is updated or published on Gov.UK's news pages.

Dafydd 1 Jan 31, 2022
radiant discord anti nuke src leaked lol.

radiant-anti-wizz-leaked radiant discord anti nuke src leaked lol, the whole anti sucks but idc. sucks to suck thats tuff bro LMAOOOOOO join my server

ok 15 Aug 06, 2022
A multipurpose, semi-modular Discord bot written in Python with the new discord.py module.

Discord.py Reaction Bot MIRAI KURIYAMA A multipurpose, semi-modular Discord bot written in Python with the new discord.py module. Installing dependenc

1 Dec 02, 2021
Бот для скачивания треков с Deezer используя ISRC и UPC коды

deez_robot Запуск Установите необходимые библиотеки pip install -r requirements.txt Создайте файл config.py и поместите туда токен бота и ARL-токен De

Max 4 Jul 31, 2022
ESOLinuxAddonManager - Very simple addon manager for Elder Scrolls Online running on Linux.

ESOLinuxAddonManager Very simple addon manager for Elder Scrolls Online running on Linux. Well, more a downloader for now. Currently it's quite ugly b

Akseli 25 Aug 28, 2022
Fix Twitter video embeds in Discord

TwitFix very basic flask server that fixes twitter embeds in discord by using youtube-dl to grab the direct link to the MP4 file and embeds the link t

Robin Universe 682 Dec 28, 2022