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
Opencontactbook - Bulk-manage large numbers of vCard contacts with built-in geolocation

Open Contact Book Open Contact Book is a buiness-oriented, cross-platform, Pytho

Aurélien PIERRE 2 Aug 08, 2022
Simple Webhook Spammer with Optional Proxy Support

😎 �Simple Webhook Spammer with Optional Proxy Support:- [+] git clone https://g

Terminal1337 12 Sep 29, 2022
A Discord bot to scrape textfiles from messages and put them to Hastebin

A Discord bot to scrape textfiles from messages and put them to Hastebin. Intended to use on support servers to help users read textfiles on mobile.

1 Jan 23, 2022
Hazard-Nuker - Hazard Nuker With Python

🌟 Since hazard is free, donations are really appriciate and keeps the developme

†† 9 Oct 26, 2022
Quickly edit your slack posts.

Lightning Edit Quickly edit your Slack posts. Heavily inspired by @KhushrajRathod's LightningDelete. Usage: Note: Before anything, be sure to head ove

Cole Wilson 14 Nov 19, 2021
Unofficial Meteor Client wiki

Welcome to the Unofficial Meteor Client wiki! Meteor FAQs | A rewritten and better FAQ page. Installation Guide | A guide on how to install Meteor Cli

Anti Cope 0 Feb 21, 2022
A results generator and automatic token checker for Yandex Contest

Yandex contest Python checking tools A results generator and automatic token checker for Yandex Contest. Версия на русском языке Installation Clone th

Nikolay Chechulin 9 Dec 14, 2022
A tool to build scripts to toggle between minimal & default services in Windows based on user defined lists.

A tool to build scripts to toggle between minimal & default services in Windows based on user defined lists.

AMIT 29 Jan 01, 2023
Bot Realm of the Mad God Exalt (ROTMG). (Auto_nexus, Auto_HP, Auto_Loot)

Bot_ROTMG Bot Realm of the Mad God Exalt (ROTMG). (Auto_nexus, Auto_HP, Auto_Loot) *Este projeto visa apenas o aprendizado, quem faz mal uso é o único

Guilherme Silva Uchoa 1 Oct 30, 2021
Telegram bot that sends new offers from otomoto.pl

Telegram bot that sends new offers under certain filters from otomoto.pl How to use this bot? Install requirements with pip install -r requirements.tx

Mikhail Zanka 1 Feb 14, 2022
Build a better understanding of your data in PostgreSQL.

Data Fluent for PostgreSQL Build a better understanding of your data in PostgreSQL. The following shows an example report generated by this tool. It g

Mark Litwintschik 28 Aug 30, 2022
ClearML - Auto-Magical Suite of tools to streamline your ML workflow. Experiment Manager, MLOps and Data-Management

ClearML - Auto-Magical Suite of tools to streamline your ML workflow Experiment Manager, MLOps and Data-Management ClearML Formerly known as Allegro T

ClearML 3.9k Jan 01, 2023
A discord.py bot template with easy deployment through Github Actions

discord.py bot template A discord.py bot template with easy deployment through Github Actions. You can use this template to just run a Python instance

Thomas Van Iseghem 1 Feb 09, 2022
Discord bot code to stop users that are scamming with fake messages of free discord nitro on servers in order to steal users accounts.

AntiScam Discord bot code to stop users that are scamming with fake messages of free discord nitro on servers in order to steal users accounts. How to

H3cJP 94 Dec 15, 2022
A simple Python wrapper for the archive.is capturing service

archiveis A simple Python wrapper for the archive.is capturing service. Installation pipenv install archiveis Python Usage Import it. import archi

PastPages 157 Dec 28, 2022
Sms-bomber - A Simple Browser Automated Bomber

A Simple Browser Automated Bomber which uses selenium :D Star the Repo and Follo

Terminal1337 9 Apr 11, 2022
Salmanul Farisx Bot With Python

Salman_Farisx_Bot How To Deploy Video Subscribe YouTube Channel Added Features Imdb posters for autofilter. Imdb rating for autofilter. Custom caption

1 Dec 23, 2021
🔎 Hunt down social media accounts by username across social networks

Hunt down social media accounts by username across social networks Installation | Usage | Docker Notes | Contributing Installation # clone the repo $

Sherlock 38.2k Jan 01, 2023
OpenSea Bulk Uploader And Trader 100000 NFTs (MAC WINDOWS ANDROID LINUX) Automatically and massively upload and sell your non-fungible tokens on OpenSea using Python Selenium

OpenSea Bulk Uploader And Trader 100000 NFTs (MAC WINDOWS ANDROID LINUX) Automatically and massively upload and sell your non-fungible tokens on OpenS

ERC-7211 3 Mar 24, 2022
Demo of using Telegram to send alert message

MIAI_Telegram Demo of using Telegram to send alert message Video link: https://youtu.be/oZ9CsIrlMgg #MìAI Fanpage: http://facebook.com/miaiblog Group

4 Jun 20, 2021