Import Notion databases to PostgreSQL tables
Project description
When a system built with Notion databases reaches a sufficient scale, the need for business intelligence arises. This requires extracting data from Notion and loading it into a relational database.
The original author didn’t find a convenient, off-the-shelf solution for this. Services offering synchronization from Notion to a relational database rely on clunky automations and involve manual configuration.
Thus notion2pg was born.
It does exactly one thing: convert any Notion database to a PostgreSQL table. It requires zero configuration. You made changes in Notion? No worries, just re-run notion2pg to refresh the table definition and its content.
While notion2pg is currently alpha software, it imported successfully complex databases with dozens of columns and thousands of rows. There’s a fair chance that it will handle any human-sized Notion database.
Quick start
Share a Notion database with your integration, as well as related databases.
Create a PostgreSQL database e.g.:
$ createuser notion $ createdb notion -O notion
Install notion2pg (requires Python ≥ 3.8):
$ pip install notion2pg
Set Notion and PostgreSQL credentials as environment variables e.g.:
$ export NOTION_TOKEN=secret_... $ export POSTGRESQL_DSN="dbname=notion user=notion"
Import your database e.g.:
$ notion2pg <database_id> <table_name>
where <database_id> can be found in the URL of your database — it’s a UUID like 858611286a7d43a197c7c0ddcc7d5a4f and <table_name> is any valid PostgreSQL table name.
Command line options
--drop-existing
Drop the PostgreSQL table if it exists. This is useful if you want to import a table repeatedly, overwriting any previous version.
--versioned
Append a timestamp to the name of the PostgreSQL table. Then, create a view pointing to that table, so it can still be queried under <table name>. This is useful if you want to import a table a repeatedly, but would rather keep previous versions around.
FAQ
Why is my relation or rollup field empty?
Your integration must have access not only to the table that you’re importing, but also to every table involved in a relation or a rollup.
Limitations
The order of columns in the table isn’t preserved. This information isn’t available in the API of Notion.
Rollups “Show original” and “Show unique values” are ignored. Import the related table and join it in your queries instead.
Properties of type “people” are imported as the person ID, which is probably not the most useful representation.
Every import is a full copy. Given that Notion’s API isn’t particularly fast, the practical limit is around 10,000 rows.
Changelog
0.1
Initial public release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for notion2pg-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a94667107b6278871035b9701f4403d9082567819609dc85087b362434e95030 |
|
MD5 | 60e6979dd5f9b353e5333743b4db3394 |
|
BLAKE2b-256 | 6e0de5b95176020d3c2b11dc7be89878c30918bc28bf5b8286a60dfc95ecf317 |