Skip to content

Instantly share code, notes, and snippets.

@iddan
Created August 20, 2019 07:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iddan/1e86a0c5310a04736a7e9e515e3e8a29 to your computer and use it in GitHub Desktop.
Save iddan/1e86a0c5310a04736a7e9e515e3e8a29 to your computer and use it in GitHub Desktop.
Notion to Pandas
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Notion_to_Pandas.ipynb",
"version": "0.3.2",
"provenance": [],
"collapsed_sections": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
}
},
"cells": [
{
"cell_type": "code",
"metadata": {
"id": "UIUDmd5p34OZ",
"colab_type": "code",
"colab": {}
},
"source": [
"%pip install notion"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "Md13fa5R36xM",
"colab_type": "code",
"colab": {}
},
"source": [
"from getpass import getpass\n",
"\n",
"print('Go to Notion.so, open developer tools, go to Application tab, Cookies, and copy the value of token_v2')\n",
"token = getpass()"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "hSw9gd-Q4Z6V",
"colab_type": "code",
"colab": {}
},
"source": [
"from notion.client import NotionClient\n",
"\n",
"notion = NotionClient(token_v2=token)\n",
"\n",
"# This is a link of a table\n",
"rows = notion.get_block(block_url).collection.get_rows()\n",
"\n",
"table_data = [row.get_all_properties() for row in rows]"
],
"execution_count": 0,
"outputs": []
},
{
"cell_type": "code",
"metadata": {
"id": "fL9ySGoV46Ah",
"colab_type": "code",
"colab": {}
},
"source": [
"import pandas as pd\n",
"\n",
"pd.DataFrame(table_data)"
],
"execution_count": 0,
"outputs": []
}
]
}
@josegarciav
Copy link

THANK YOU

@VianneyMI
Copy link

I get an HTTP Error (400) when I try to do something similar

@iddan
Copy link
Author

iddan commented Feb 8, 2022

@VianneyMI can you please elaborate?

@VianneyMI
Copy link

@iddan whenever I use the get_block method I get an HTTP Error as shown below
image

@unchs
Copy link

unchs commented Nov 24, 2022

Nice work!

Any plans on when this feature gets implemented ?
if mode not in ("a", "append"):
raise NotImplementedError
# TODO: clean the current values in the notion database (if any)

@VianneyMI
Copy link

@unchs

Notion has released an official API now, you can use it, even though it also comes with its own set of challenges
https://developers.notion.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment