Export Notion pages to a Roam-Research like graph view.
- Python >= 3.9
pip install notion-graph
-
Create a notion internal integration and generate an
Internal Integration Token
. -
Open one notion page on browser, select "Add connections" and add your integration account.
-
Find your base
Page ID
from browser url, for example:
if page url is: https://www.notion.so/yourName/PageTitle-8a4b5ff100d648fb8d39d4bfa756ff3f,
8a4b5ff100da48fb8d39d4bfa756ff3f
is thePage ID
python -m notion_graph -p <Page ID> -t <Integration Token> -o <PNG file path to export>
For instance,
python -m notion_graph -p 856391c93ae64bd1b7ebf699ca0cd861 -t secret_b8p7uLp3j3n95IDgofC9GviXP111Skx6NOt2d20U8e -o ./graph_out.png
graph_out.png
would be generated at your specific path.
Matplotlib by default does not support displaying Unicode characters. To resolve this issue, specify your local font family by using -f
:
python -m notion_graph -p 856391c93ae64bd1b7ebf699ca0cd861 -t secret_b8p7uLp3j3n95IDgofC9GviXP111Skx6NOt2d20U8e -o ./graph_out.png -f 'SimSun'
You can also import notion_graph
as a library.
For instance, drawing your own diagram by matplotlib.
import notion_graph as ng
import networkx as nx
import matplotlib.pyplot as plt
my_ng = ng.NotionGraph(bearer_token="secret_b8p7uLp3j3n95IDgofC9GviXP111Skx6NOt2d20U8e")
graph = my_ng.parse(page_id="856391c93ae64bd1b7ebf699ca0cd861")
# graph is a networkx.classes.graph.Graph object
pos = nx.spring_layout(graph)
labels = nx.get_node_attributes(graph, 'title')
options = {
"node_size": 50,
"node_color": "tab:gray",
"font_size": 10,
"width": 0.5,
"with_labels": True,
"labels": labels
}
nx.draw(graph, pos, **options)
plt.show()
plt.savefig('./graph.png')
The testing page is Notion-grap-view-demo. You can duplicate the page to your Notion account and run the project to test if everything goes well.
This project's dependencies are managed by PDM.
brew install pdm
pdm install
Running the project by:
pdm run start -p <page_id> -t <notion_token> -o ./graph_out.png
database | page | |
---|---|---|
paragraph | โ๏ธ | โ๏ธ |
bulleted_list_item | โ๏ธ | โ๏ธ |
numbered_list_item | โ๏ธ | โ๏ธ |
to_do | โ๏ธ | โ๏ธ |
toggle | โ๏ธ | โ๏ธ |
child_page | โ๏ธ | โ๏ธ |
child_database | โ๏ธ | โ๏ธ |
embed | ||
callout | โ๏ธ | โ๏ธ |
quote | โ๏ธ | โ๏ธ |
heading_1 | โ๏ธ | โ๏ธ |
heading_2 | โ๏ธ | โ๏ธ |
heading_3 | โ๏ธ | โ๏ธ |
column | ||
column_list | ||
synced_block | ||
link_to_page | ||
table | โ๏ธ | โ๏ธ |
table_row | โ๏ธ | โ๏ธ |