Notion API Database Python Implementation

Overview

Python Notion Database

Notion API Database Python Implementation

created only by database from the official Notion API.

Installing / Getting started

pip install notion-database
import os
import pprint

from notion_database.database import Database
from notion_database.page import Page
from notion_database.properties import Properties, Children

try:
    from dotenv import load_dotenv

    load_dotenv()
except ModuleNotFoundError:
    pass

NOTION_KEY = os.getenv('NOTION_KEY')

PROPERTY = Properties()
PROPERTIES = {
    "name": PROPERTY.set_title("title"),
    "description": PROPERTY.set_rich_text("description"),
    "number": PROPERTY.set_number(1),
    "select": PROPERTY.set_select("test1"),
    "multi_select": PROPERTY.set_multi_select(["test1", "test2"]),
    "checkbox": PROPERTY.set_checkbox(True),
    "url": PROPERTY.set_url("www.google.com"),
    "email": PROPERTY.set_email("[email protected]"),
    "phone": PROPERTY.set_phone_number("010-0000-0000"),
}

# List Database
D = Database(integrations_token=NOTION_KEY)
D.list_databases(page_size=100)

for i in D.result["results"]:
    database_id = i["id"]

    # Retrieve Database
    D = Database(integrations_token=NOTION_KEY)
    D.retrieve_database(database_id=database_id)
    pprint.pprint(D.result)

    # Create Page
    P = Page(integrations_token=NOTION_KEY, database_id=database_id)
    P.create_page(properties=PROPERTIES, children=[Children().set_body("hello world!")])

    # Retrieve Page
    page_id = P.result["id"]
    P.retrieve_page(page_id=page_id)
    pprint.pprint(P.result)

    PROPERTIES = {
        "name": PROPERTY.set_title("Custom_title"),
        "description": PROPERTY.set_rich_text("Custom_description"),
        "number": PROPERTY.set_number(2),
    }

    # Update Page
    P.update_page(page_id=page_id, properties=PROPERTIES)
    pprint.pprint(P.result)

Building / Developing

python setup.py install

Features

  • list database

  • Retrieve database

  • Create Page object (the database item)

  • update Page object

  • Retrieve Page object

Todo

  • query database

Contributing

If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are warmly welcome.

Links

Licensing

The code in this project is licensed under GPL license.

Comments
  • Adding advanced children blocks

    Adding advanced children blocks

    First of all, thanks for the package - it's crisp and to the point 👍

    So while playing around with the code, I tried to create a new page with some "complex" content (Children) that could be a combination of text, embed elements, etc. Currently, it seems the Children class only supports normal text, I was thinking is it possible to add support for other blocks as well?

    Btw I managed to create a workaround for my task using the following class,

    class NewChildren:
        result = []
    
        def add_text(self, text):
            self.result.append({'object': 'block',
             'type': 'paragraph',
             'paragraph': {'text': [{'type': 'text',
             'text': {'content': text}}]}})
    
        def add_embed(self, link):
            self.result.append({'object': 'block',
             'type': 'embed',
             'embed': {'url': link}})
    

    Maybe something on similar lines? Thanks again!

    enhancement 
    opened by imohitmayank 4
  • Update setup.py

    Update setup.py

    Hi @minwook-shin . I am building a library on top of yours and it looks liked you missed adding your requirements to install_require array in setup.py. This leads to the requests library not being installed when you pip install the library. If you want to see the effect this change has you can run the cmds below in a venv.

    python3 -m venv venv /venv/bin/pip3 install git+https://github.com/potofpie/notion-database/tree/potofpie-patch-1#egg=notion_database

    opened by potofpie 2
  • No results returned with `list_databases()`

    No results returned with `list_databases()`

    Hello! This seems like an awesome package!

    Unfortunately I can't seem to get it to work on my end. See screenshot when I follow the example with list_databases(): image

    Any thoughts around why I'm not seeing any results returned here? I have plenty of databases in my Notion of course, and you can see if I show the result of D it seems to be a notion_database.database.Database object which seems correct.

    I can't seem to get other endpoints like the one to retrieve a specific page to work either. Any guidance you could provide around what I'm missing here?

    Thank you! Ricky

    opened by RickyEsclapon 2
  • Bug in Properties class to set_checkbox

    Bug in Properties class to set_checkbox

    Hi,

    I think i found a bug in the properties class. I tried to unset the checkbox in one of my notion databases. I alway got a validation erros because the set_checkbox function will always replace the 'False' value with a dict:

    example:

    PROPERTY = Properties()
    ROPERTY.set_checkbox("Checkbox, False)
    
    P = Page(integrations_token=NOTION_KEY)
    P.retrieve_page(page_id=page_id)
    P.update_page(page_id=page_id, properties=PROPERTY)
    

    This example always resulted in the follwoing errror message:

    grafik

    I was able to resolve this by changing the default value in the set_checkbox function to 'False'

        def set_checkbox(self, col, text=None):
            """
            checkbox configuration
    
            :param col: column name
            :param text: page text. If no text is given, for database only.
            :return:
            """
            if not text:
                text = False #! changed this from {} to 'False'
            self.result.update({col: {"checkbox": text}})
    
    

    I´m not sure If I made somthing wrong or there was a change in the notion API.

    bug 
    opened by BMeyn 1
  • Unable to update Database's properties

    Unable to update Database's properties

    Hi; I have the following code

    PROPERTY = Properties() D.update_database(database_id=database_id, title="DB", add_properties=PROPERTY) print(pprint.pformat(D.properties_list)) The database_id and the Database itself are good; because the "D.properties_list" give me back all the properties in my print. But without the default property from your class. I also cannot find a way to check if the function "D.update_database" succeeded or not

    This is the output of D.properties_list printed: [{'id': '%3BoW%60', 'name': 'Street Line 1', 'rich_text': {}, 'type': 'rich_text'}, {'id': '%3B%7DLp', 'name': 'Street Line 2', 'rich_text': {}, 'type': 'rich_text'}, {'id': 'DBzM', 'name': 'Customer', 'rich_text': {}, 'type': 'rich_text'}, {'id': 'Eps%7C', 'name': 'Status', 'rich_text': {}, 'type': 'rich_text'}, {'id': 'LkwZ', 'name': 'Postal Code', 'rich_text': {}, 'type': 'rich_text'}, {'id': 'L%7BQj', 'name': 'locality', 'rich_text': {}, 'type': 'rich_text'}, {'id': 'O%3AV%3F', 'name': 'Street Line 3', 'rich_text': {}, 'type': 'rich_text'}, {'id': 'OniY', 'name': 'Adress', 'rich_text': {}, 'type': 'rich_text'}, {'id': '%5CZ%5Cf', 'name': 'City', 'rich_text': {}, 'type': 'rich_text'}, {'id': '%60Q%7C_', 'name': 'Content', 'rich_text': {}, 'type': 'rich_text'}, {'id': '%60y%3B%7D', 'name': 'short_locality', 'rich_text': {}, 'type': 'rich_text'}, {'id': 'gGxD', 'name': 'Country', 'rich_text': {}, 'type': 'rich_text'}, {'id': 'pBA%7B', 'name': 'iso_code', 'rich_text': {}, 'type': 'rich_text'}, {'id': 'v%7BYP', 'name': 'Size', 'rich_text': {}, 'type': 'rich_text'}]

    opened by SovnSkyrim 0
  • Adds extra features

    Adds extra features

    Adds support for Files Property. Adds colors parameters for supported Children

    Important Notion API does not support file upload yet. You must use external url to the file.

    opened by joelschutz 0
  • relation objects not displayed

    relation objects not displayed

    Hi! When I am trying to parse a database that has fields of type 'relation', the 'relation' objects are always returned empty even if it is not the case in the database, and so I cannot obtain the value associated with the 'relation' object. Is there any way go obtain the link if I have access to both databases?

    enhancement 
    opened by viktortsvil 0
  • Retrieve databases from a page

    Retrieve databases from a page

    Hello, I tried to use notion-database to retrieve data from my notion. My notion is a little bit complicated. The main page has several databases, each of which has several pages, and each of which has a database. I use find_all_pages to retrieve pages from the databases, but I want to know if I can retrieve databases from the pages and how. Thank you.

    Here's the structure sample of my Notion database: Notion

    help wanted question 
    opened by alisongh 1
Owner
minwook
launchpad.net/~minwook-shin
minwook
Notion API Database Python Implementation

Python Notion Database Notion API Database Python Implementation created only by database from the official Notion API. Installing / Getting started p

minwook 78 Dec 19, 2022
Unofficial Python API client for Notion.so

notion-py Unofficial Python 3 client for Notion.so API v3. Object-oriented interface (mapping database tables to Python classes/attributes) Automatic

Jamie Alexandre 3.9k Jan 3, 2023
Python 3 tools for interacting with Notion API

NotionDB Python 3 tools for interacting with Notion API: API client Relational database wrapper Installation pip install notiondb API client from noti

Viet Hoang 14 Nov 24, 2022
A small repository with convenience functions for working with the Notion API.

Welcome! Within this respository are a few convenience functions to assist with the pulling and pushing of data from the Notion API.

null 10 Jul 9, 2022
A small Python app to create Notion pages from Jira issues

Jira to Notion This little program will capture a Jira issue and create a corresponding Notion subpage. Mac users can fetch the current issue from the

Dr. Kerem Koseoglu 12 Oct 27, 2022
Discord RPC for Notion written in Python

Discord RPC for Notion This is a program that allows you to add your Notion workspace activities to your Discord profile. This project is currently un

Thuliumitation 1 Feb 10, 2022
A way to export your saved reddit posts to a Notion table.

reddit-saved-to-notion A way to export your saved reddit posts and comments to a Notion table.Uses notion-sdk-py and praw for interacting with Notion

null 19 Sep 12, 2022
Import Notion Tasks to

Notion-to-Google-Calendar (1 way) Import Notion Tasks to Google Calendar NO MORE UPDATES WILL BE MADE TO THIS REPO. Attention has been put on a 2-way

null 12 Aug 11, 2022
A simple object model for the Notion SDK.

A simplified object model for the Notion SDK. This is loosely modeled after concepts found in SQLAlchemy.

Jason Heddings 54 Jan 2, 2023
Token-gate Notion pages

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

John 8 Oct 13, 2022
A script to automate the process of downloading Markdown and CSV backups of Notion

Automatic-Notion-Backup A script to automate the process of downloading Markdown and CSV backups of Notion. In addition, the data is processed to remo

Jorge Manuel Lozano Gómez 2 Nov 2, 2022
A small package to markdownify Notion blocks.

markdownify-notion A small package to markdownify notion blocks. Installation Install this library using pip: $ pip install markdownify-notion Usage

Sergio Sánchez Zavala 2 Oct 29, 2022
Notflix - Notion / Netflix and IMDb to organise your movie dates. Happy Valentine <3 from 0x1za

Welcome to notflix ?? This is a project to help organise shows to watch with my

Mwiza Ed' Simbeye 3 Feb 15, 2022
A wrapper for The Movie Database API v3 and v4 that only uses the read access token (not api key).

fulltmdb A wrapper for The Movie Database API v3 and v4 that only uses the read access token (not api key). Installation Use the package manager pip t

Jacob Hale 2 Sep 26, 2021
Stock market bot that will be used to learn about API calls and database connections.

Stock market bot that will be used to learn about API calls and database connections.

null 1 Dec 24, 2021
IMDbPY is a Python package useful to retrieve and manage the data of the IMDb movie database about movies, people, characters and companies

IMDbPY is a Python package for retrieving and managing the data of the IMDb movie database about movies, people and companies. Revamp notice Starting

Davide Alberani 1.1k Jan 2, 2023
A modular Telegram Python bot running on python3 with a sqlalchemy, redislab, mongo database, telethon, and pyrogram.

Zeldris Robot A modular Telegram Python bot running on python3 with a sqlalchemy, redislab, mongo database, telethon, and pyrogram. How to set up/depl

IDNCoderX 42 Dec 21, 2022
A modular Telegram Python bot running on python3 with a sqlalchemy database

Nao Tomori Robot Found Me On Telegram As Nao Tomori ?? A modular Telegram Python bot running on python3 with a sqlalchemy database. How to setup/deplo

Sena 84 Jan 4, 2023