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
A collection of scripts to steal BTC from Lightning Network enabled custodial services. Only for educational purpose! Share your findings only when design flaws are fixed.

Lightning Network Fee Siphoning Attack LN-fee-siphoning is a collection of scripts to subtract BTC from Lightning Network enabled custodial services b

Reckless_Satoshi 14 Oct 15, 2022
Discord group chat spammer concept.

GC Spammer [Concept] GC-Spammer for https://discord.com/ Warning: This is purely a concept. In the past the script worked, however, Discord ratelimite

Roover 3 Feb 28, 2022
AWS-serverless-starter - AWS Lambda serverless stack via Serverless framework

Serverless app via AWS Lambda, ApiGateway and Serverless framework Configuration

Bəxtiyar 3 Feb 02, 2022
McTrade is a bot exploiting Binance API, open source! built in python !

Open Source Crypto Trading Bot using Binance API Report Bug · Request Feature Table of Contents About The Project Built With Getting Started Prerequis

Raphael Cohen 5 Jul 17, 2022
GitGram Bot. Bot Then Message You Your Repo Starts, Forks, And Many More

Yet Another GitAlertBot Inspired From Dev-v2's GitGram Run Bot: Local Host Git Clone Repo : For Telethon Version : git clone https://github.com/TeamAl

Alina RoBot 2 Nov 24, 2021
A simple Discord Mass-Ban that's still working with Member Scraper.

Mass-Ban [!] This was made for education / you can use for revenge. Please don't skid it. [!] If you want to use it, please use member scraper before

WoahThatsHot 1 Nov 20, 2021
A program to convert YouTube channel registration information into Json files for ThirdTube.

ThirdTubeImporter A program to convert YouTube channel registration information into Json files for ThirdTube. Usage Japanese https://takeout.google.c

Hidegon 2 Dec 18, 2021
𝗖𝝠𝝦𝝩𝝠𝝞𝝥 𝝦𝗥𝝞𝗖𝝽°™️ 🇱🇰 Is An All In One Media Inline Bot Made For Inline Your Media Effectively With Some Advance Security Tools♥️

𝗖𝝠𝝦𝝩𝝠𝝞𝝥 𝝦𝗥𝝞𝗖𝝽° ™️ 🇱🇰 𝗙𝗘𝝠𝝩𝗨𝗥𝗘𝗦 Auto Filter IMDB Admin Commands Broadcast Index IMDB Search Inline Search Random Pics Ids & User I

Kɪꜱᴀʀᴀ Pᴇꜱᴀɴᴊɪᴛʜ Pᴇʀᴇʀᴀ 〄 13 Jun 21, 2022
pylunasvg - Python bindings for lunasvg

pylunasvg - Python bindings for lunasvg Pylunasvg is a simple wrapper around lunasvg that uses pybind11 to create python bindings. All public API of t

Eren 6 Jan 05, 2023
AnyAPI is a library that helps you to write any API wrapper with ease and in pythonic way.

AnyAPI AnyAPI is a library that helps you to write any API wrappers with ease and in pythonic way. Features Have better looking code using dynamic met

Fatih Kilic 129 Sep 20, 2022
Finds Jobs on LinkedIn using web-scraping

Find Jobs on LinkedIn 📔 This program finds jobs by scraping on LinkedIn 👨‍💻 Relies on User Input. Accepts: Country, City, State 📑 Data about jobs

Matt 44 Dec 27, 2022
Python wrapper for Coinex APIs

coinexpy - Python wrapper for Coinex APIs Through coinexpy you can simply buy or sell crypto in your Coinex account Features place limit order place m

Iman Mousaei 16 Jan 02, 2023
Simple Telegram AI Chat bot made using OpenAI and Luna API

Yui Yui, is a simple telegram chat bot made using OpenAI and Luna Chat bot Deployment 👀 Deploying is easy 🤫 ! You can deploy this bot in Heroku or i

I'm Not A Bot #Left_TG 21 Dec 29, 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
A Dm Bot, also knows as Mass DM bot which can send one message to All of the Users in a Specific Server!

Discord DM Bot discord.py 1.7.2 python 3.9.5 asyncio 3.4.3 Installation Cloud Host Tutorial uploaded in YouTube, watch it by clicking here. Local Host

hpriyam8 7 Mar 24, 2022
Discord bot to display private leaderboards for Advent of Code.

Advent Of Code Discord Bot Discord bot for displaying Advent of Code private leardboards, as well as custom leaderboards where participants can set th

The Future Gadgets Lab 6 Nov 29, 2022
An implementation of webhook used to notify GitHub repository events to DingTalk.

GitHub to DingTask An implementation of webhook used to notify GitHub repository events to DingTalk.

Prodesire 5 Oct 02, 2022
Telegram File to Link Fastest Bot , also used for movies streaming

Telegram File Stream Bot ! A Telegram bot to stream files to web. Report a Bug | Request Feature About This Bot This bot will give you stream links fo

Avishkar Patil 194 Jan 07, 2023
An almost dependency-less, synchronous Discord gateway library meant for my personal use

An almost dependency-less, synchronous Discord gateway library meant for my personal use.

h0nda 4 Feb 05, 2022
A Telegram Bot written in Python for mirroring files on the Internet to your Google Drive

No support is going to be provided of any kind, only maintaining this for vps user on request. This is a Telegram Bot written in Python for mirroring

Sunil Kumar 42 Oct 28, 2022