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 notionInstall notion2pg (requires Python ≥ 3.8):
$ pip install notion2pgSet 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.
Release files for notion2pg 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| notion2pg-0.1.0.tar.gz | 9.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| notion2pg-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 17.8 kB
Release files / notion2pg-0.1.0.tar.gz
| Download URL | notion2pg-0.1.0.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c193588084089c5cae9b25ba66e97d8ad97c449f805f6d0628b4cc674c294a08
|
|
BLAKE2b-256 checksum How to use checksums |
b8126257ee8d41573f33a1c950ae59a7f6f461350802bcf1f1b3cd7fa75314eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.10.2 Darwin/21.3.0
|
Release files / notion2pg-0.1.0-py3-none-any.whl
| Download URL | notion2pg-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a94667107b6278871035b9701f4403d9082567819609dc85087b362434e95030
|
|
BLAKE2b-256 checksum How to use checksums |
6e0de5b95176020d3c2b11dc7be89878c30918bc28bf5b8286a60dfc95ecf317
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.13 CPython/3.10.2 Darwin/21.3.0
|