notion-df: Seamlessly Connecting Notion Database with Pandas DataFrame
Please Note: This project is currently in pre-alpha stage. The code are not appropriately documented and tested. Please report any issues you find. Thanks!
Installation
pip install notion-df
Usage
-
Before starting, please follow the instructions to create a new integration and add it to your Notion page or database.
- We'll refer
Internal Integration Tokenas theapi_keybelow.
- We'll refer
-
Pandas-flavored APIs: Just need to add two additional lines of code:
import notion_df notion_df.pandas() #That's it! page_url = "paste your page url from Notion" api_key = "paste your api key (internal integration key)" import pandas as pd df = pd.read_notion(page_url, api_key=api_key) df.to_notion(page_url, api_key=api_key)
-
Download your Notion table as a pandas DataFrame
import notion_df df = notion_df.download(notion_database_url, api_key=api_key) # Equivalent to: df = pd.read_notion(notion_database_url, api_key=api_key) df.head()
Only downloading the first `nrows` from a database
df = notion_df.download(notion_database_url, nrows=nrows) #e.g., 10
What if your table has a relation column?
df = notion_df.download(notion_database_url, resolve_relation_values=True)
The
resolve_relation_values=Truewill automatically resolve the linking for all the relation columns whose target can be accessed by the current notion integration.In details, let's say the
"test"column in df is a relation column in Notion.- When
resolve_relation_values=False, the return results for that column will be a list of UUIDs of the target page:['65e04f11-xxxx', 'b0ffcb4b-xxxx', ]. - When
resolve_relation_values=True, the return results for that column will be a list of regular strings corresponding to the name column of the target pages:['page1', 'page2', ].
- When
-
Append a local
dfto a Notion database:import notion_df notion_df.upload(df, notion_database_url, title="page-title", api_key=api_key) # Equivalent to: df.to_notion(notion_database_url, title="page-title", api_key=api_key)
-
Upload a local
dfto a newly created database in a Notion page:import notion_df notion_df.upload(df, notion_page_url, title="page-title", api_key=api_key) # Equivalent to: df.to_notion(notion_page_url, title="page-title", api_key=api_key)
-
Tired of typing
api_key=api_keyeach time?import notion_df notion_df.config(api_key=api_key) # Or set an environment variable `NOTION_API_KEY` df = notion_df.download(notion_database_url) notion_df.upload(df, notion_page_url, title="page-title") # Similarly in pandas APIs: df.to_notion(notion_page_url, title="page-title")
Development
- Clone the repo and install the dependencies:
git clone git@github.com:lolipopshock/notion-df.git cd notion-df pip install -e .[dev]
- How to run tests?
NOTION_API_KEY="<the-api-key>" pytest tests/
The tests are dependent on a list of notebooks, specified by the following environment variables:
| Environment Variable | Description |
|---|---|
NOTION_API_KEY |
The API key for your Notion integration |
NOTION_ROLLUP_DF |
- |
NOTION_FILES_DF |
- |
NOTION_FORMULA_DF |
- |
NOTION_RELATION_DF |
- |
NOTION_RELATION_TARGET_DF |
- |
NOTION_LONG_STRING_DF |
- |
NOTION_RICH_TEXT_DF |
- |
TODOs
- Add tests for
-
load -
upload -
values.py -
configs.py -
base.py
-
- Better class organizations/namings for
*Configsand*Values
Metadata
Release files for notion-df-extended 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 | |
|---|---|---|---|
| notion_df_extended-0.1.0.tar.gz | 19.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| notion_df_extended-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 41.7 kB
Release files / notion_df_extended-0.1.0.tar.gz
| Download URL | notion_df_extended-0.1.0.tar.gz |
|---|---|
| Size | 19.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f85d56162040bb5be9af7abede3122616d5f1439a767227e35bd54d08e69c193
|
|
BLAKE2b-256 checksum How to use checksums |
e596c3ecc2ced6b91037330e53da0d9cb1a3ccbfcfeb8b0b9f6ac4dcb82a8a2b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.2 CPython/3.10.8 Darwin/22.4.0
|
Release files / notion_df_extended-0.1.0-py3-none-any.whl
| Download URL | notion_df_extended-0.1.0-py3-none-any.whl |
|---|---|
| Size | 21.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5f19b317e34c42998a7b19fe52f0e61529336514b23e607abecfac29ee032841
|
|
BLAKE2b-256 checksum How to use checksums |
8b5aa5e4f59daf59a3bf842ad3bea0a542c6f6038d3b56588b0700c8c6ad71f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.3.2 CPython/3.10.8 Darwin/22.4.0
|