notion-cascade-insert 0.0.1__tar.gz → 0.0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {notion_cascade_insert-0.0.1/notion_cascade_insert.egg-info → notion_cascade_insert-0.0.3}/PKG-INFO +3 -22
- notion_cascade_insert-0.0.3/README.md +75 -0
- {notion_cascade_insert-0.0.1 → notion_cascade_insert-0.0.3}/notion_cascade_insert/__init__.py +1 -1
- {notion_cascade_insert-0.0.1 → notion_cascade_insert-0.0.3}/notion_cascade_insert/_modidx.py +2 -0
- {notion_cascade_insert-0.0.1 → notion_cascade_insert-0.0.3}/notion_cascade_insert/core.py +21 -3
- {notion_cascade_insert-0.0.1 → notion_cascade_insert-0.0.3/notion_cascade_insert.egg-info}/PKG-INFO +3 -22
- {notion_cascade_insert-0.0.1 → notion_cascade_insert-0.0.3}/settings.ini +3 -3
- notion_cascade_insert-0.0.1/README.md +0 -94
- {notion_cascade_insert-0.0.1 → notion_cascade_insert-0.0.3}/LICENSE +0 -0
- {notion_cascade_insert-0.0.1 → notion_cascade_insert-0.0.3}/MANIFEST.in +0 -0
- {notion_cascade_insert-0.0.1 → notion_cascade_insert-0.0.3}/notion_cascade_insert/webhook.py +0 -0
- {notion_cascade_insert-0.0.1 → notion_cascade_insert-0.0.3}/notion_cascade_insert.egg-info/SOURCES.txt +0 -0
- {notion_cascade_insert-0.0.1 → notion_cascade_insert-0.0.3}/notion_cascade_insert.egg-info/dependency_links.txt +0 -0
- {notion_cascade_insert-0.0.1 → notion_cascade_insert-0.0.3}/notion_cascade_insert.egg-info/entry_points.txt +0 -0
- {notion_cascade_insert-0.0.1 → notion_cascade_insert-0.0.3}/notion_cascade_insert.egg-info/not-zip-safe +0 -0
- {notion_cascade_insert-0.0.1 → notion_cascade_insert-0.0.3}/notion_cascade_insert.egg-info/requires.txt +0 -0
- {notion_cascade_insert-0.0.1 → notion_cascade_insert-0.0.3}/notion_cascade_insert.egg-info/top_level.txt +0 -0
- {notion_cascade_insert-0.0.1 → notion_cascade_insert-0.0.3}/pyproject.toml +0 -0
- {notion_cascade_insert-0.0.1 → notion_cascade_insert-0.0.3}/setup.cfg +0 -0
- {notion_cascade_insert-0.0.1 → notion_cascade_insert-0.0.3}/setup.py +0 -0
{notion_cascade_insert-0.0.1/notion_cascade_insert.egg-info → notion_cascade_insert-0.0.3}/PKG-INFO
RENAMED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: notion_cascade_insert
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.3
|
|
4
4
|
Summary: Cascade inserting for Notion Database Automation (as log)
|
|
5
5
|
Home-page: https://github.com/amezaikupan/notion_cascade_insert
|
|
6
|
-
Author:
|
|
7
|
-
Author-email:
|
|
6
|
+
Author: TN
|
|
7
|
+
Author-email: amezaikupan@gmail.com
|
|
8
8
|
License: Apache-2.0
|
|
9
9
|
Keywords: nbdev jupyter notebook python
|
|
10
10
|
Classifier: Development Status :: 4 - Beta
|
|
@@ -47,25 +47,6 @@ Dynamic: summary
|
|
|
47
47
|
! pip install notion_cascade_insert
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
Requirement already satisfied: notion_cascade_insert in /app/data/.local/lib/python3.12/site-packages (0.0.1)
|
|
51
|
-
Requirement already satisfied: fastcore in /usr/local/lib/python3.12/site-packages (from notion_cascade_insert) (1.12.2)
|
|
52
|
-
Requirement already satisfied: fastapi in /usr/local/lib/python3.12/site-packages (from notion_cascade_insert) (0.128.0)
|
|
53
|
-
Requirement already satisfied: notion_client in /app/data/.local/lib/python3.12/site-packages (from notion_cascade_insert) (2.7.0)
|
|
54
|
-
Requirement already satisfied: starlette<0.51.0,>=0.40.0 in /app/data/.local/lib/python3.12/site-packages (from fastapi->notion_cascade_insert) (0.50.0)
|
|
55
|
-
Requirement already satisfied: pydantic>=2.7.0 in /usr/local/lib/python3.12/site-packages (from fastapi->notion_cascade_insert) (2.12.5)
|
|
56
|
-
Requirement already satisfied: typing-extensions>=4.8.0 in /usr/local/lib/python3.12/site-packages (from fastapi->notion_cascade_insert) (4.15.0)
|
|
57
|
-
Requirement already satisfied: annotated-doc>=0.0.2 in /usr/local/lib/python3.12/site-packages (from fastapi->notion_cascade_insert) (0.0.4)
|
|
58
|
-
Requirement already satisfied: anyio<5,>=3.6.2 in /usr/local/lib/python3.12/site-packages (from starlette<0.51.0,>=0.40.0->fastapi->notion_cascade_insert) (4.12.1)
|
|
59
|
-
Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.12/site-packages (from anyio<5,>=3.6.2->starlette<0.51.0,>=0.40.0->fastapi->notion_cascade_insert) (3.11)
|
|
60
|
-
Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.12/site-packages (from pydantic>=2.7.0->fastapi->notion_cascade_insert) (0.7.0)
|
|
61
|
-
Requirement already satisfied: pydantic-core==2.41.5 in /usr/local/lib/python3.12/site-packages (from pydantic>=2.7.0->fastapi->notion_cascade_insert) (2.41.5)
|
|
62
|
-
Requirement already satisfied: typing-inspection>=0.4.2 in /usr/local/lib/python3.12/site-packages (from pydantic>=2.7.0->fastapi->notion_cascade_insert) (0.4.2)
|
|
63
|
-
Requirement already satisfied: packaging in /usr/local/lib/python3.12/site-packages (from fastcore->notion_cascade_insert) (25.0)
|
|
64
|
-
Requirement already satisfied: httpx>=0.23.0 in /usr/local/lib/python3.12/site-packages (from notion_client->notion_cascade_insert) (0.28.1)
|
|
65
|
-
Requirement already satisfied: certifi in /usr/local/lib/python3.12/site-packages (from httpx>=0.23.0->notion_client->notion_cascade_insert) (2026.1.4)
|
|
66
|
-
Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.12/site-packages (from httpx>=0.23.0->notion_client->notion_cascade_insert) (1.0.9)
|
|
67
|
-
Requirement already satisfied: h11>=0.16 in /usr/local/lib/python3.12/site-packages (from httpcore==1.*->httpx>=0.23.0->notion_client->notion_cascade_insert) (0.16.0)
|
|
68
|
-
|
|
69
50
|
## How to use
|
|
70
51
|
|
|
71
52
|
### Building blocks
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Notion Cascade Insert
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
|
|
5
|
+
|
|
6
|
+
## Installing
|
|
7
|
+
|
|
8
|
+
``` python
|
|
9
|
+
! pip install notion_cascade_insert
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## How to use
|
|
13
|
+
|
|
14
|
+
### Building blocks
|
|
15
|
+
|
|
16
|
+
This package is built to emulate the `Notion Automation` function but
|
|
17
|
+
with one to many relation. I built this to track the transactions (hence
|
|
18
|
+
the log) that involves calculating in case where there is an big object
|
|
19
|
+
that map to many other objects, like when you have a recipe and you want
|
|
20
|
+
to get the ingredients, or when you have a lists of guests and you want
|
|
21
|
+
to get their details… This helps you manage the ammoun of stuff that
|
|
22
|
+
relate to that big object.
|
|
23
|
+
|
|
24
|
+
There are 4 of the pipelines:
|
|
25
|
+
|
|
26
|
+
1. **TriggerDB**: monitors a database for status changes
|
|
27
|
+
2. **JunctionDB**: looks up related items and amounts
|
|
28
|
+
3. **LogDB**: writes transaction logs
|
|
29
|
+
4. **AutoLogger**: orchestrates the flow
|
|
30
|
+
|
|
31
|
+
We can than use them to connect to `Notion Webhook` and create the
|
|
32
|
+
functions that we want.
|
|
33
|
+
|
|
34
|
+
### Example
|
|
35
|
+
|
|
36
|
+
<!-- <img src="img/mermaid-diagram-2026-01-24-213107.png"> -->
|
|
37
|
+
|
|
38
|
+
<img src="img/mermaid-diagram-2026-01-24-213107.png" style="width: 100%; height: auto; max-height: none;">
|
|
39
|
+
|
|
40
|
+
Let’s say we’re building a Bakery Inventory management database, and we
|
|
41
|
+
want our `Production Plan` database to automatically log the used
|
|
42
|
+
ingredients in a recipe that we want to make. This is a one-to-many
|
|
43
|
+
behavior, which Notion don’t support at the momment. For this, we would
|
|
44
|
+
do something like:
|
|
45
|
+
|
|
46
|
+
``` python
|
|
47
|
+
from notion_cascade_insert.core import TriggerDB, JunctionDB, LogDB, AutoLogger
|
|
48
|
+
from notion_cascade_insert.webhook import NotionWebhook
|
|
49
|
+
from fastapi import FastAPI, Request
|
|
50
|
+
from notion_client import Client
|
|
51
|
+
import os
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
``` python
|
|
55
|
+
notion = Client(auth=os.getenv("NOTION_TOKEN"))
|
|
56
|
+
|
|
57
|
+
trigger = TriggerDB(os.getenv("PRODUCTION_PLAN_DB_ID"), notion, "Status", "Recipes", "Batches to make")
|
|
58
|
+
junction = JunctionDB(os.getenv("RECIPE_INGREDIENTS_DB_ID"), notion, "Recipes", "Ingredient Inventory", "Amount per batch")
|
|
59
|
+
log = LogDB(os.getenv("INGREDIENT_TRANSACTION_DB"), notion, "Ingredient", "Amount", "Production Plan", "Reason")
|
|
60
|
+
db_logger = AutoLogger(trigger, junction, log, "In Process", -1)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
This will create your Ingredient Logger! Then you can set up your server
|
|
64
|
+
like so:
|
|
65
|
+
|
|
66
|
+
``` python
|
|
67
|
+
app = FastAPI()
|
|
68
|
+
|
|
69
|
+
@app.post("/webhook")
|
|
70
|
+
async def webhook(request: Request):
|
|
71
|
+
hook = NotionWebhook(await request.json())
|
|
72
|
+
if hook.parent_db_id == os.getenv("PRODUCTION_PLAN_DB_ID"):
|
|
73
|
+
if hook.type == 'page.created': return {"result": db_logger.process(hook.entity_id)}
|
|
74
|
+
return {"status": "received"}
|
|
75
|
+
```
|
{notion_cascade_insert-0.0.1 → notion_cascade_insert-0.0.3}/notion_cascade_insert/_modidx.py
RENAMED
|
@@ -20,6 +20,8 @@ d = { 'settings': { 'branch': 'main',
|
|
|
20
20
|
'notion_cascade_insert.core.Database': ('core.html#database', 'notion_cascade_insert/core.py'),
|
|
21
21
|
'notion_cascade_insert.core.Database.__init__': ( 'core.html#database.__init__',
|
|
22
22
|
'notion_cascade_insert/core.py'),
|
|
23
|
+
'notion_cascade_insert.core.Database.check_db_exists': ( 'core.html#database.check_db_exists',
|
|
24
|
+
'notion_cascade_insert/core.py'),
|
|
23
25
|
'notion_cascade_insert.core.Database.get_schema': ( 'core.html#database.get_schema',
|
|
24
26
|
'notion_cascade_insert/core.py'),
|
|
25
27
|
'notion_cascade_insert.core.JunctionDB': ( 'core.html#junctiondb',
|
|
@@ -13,6 +13,10 @@ class Database:
|
|
|
13
13
|
notion # Notion client instance
|
|
14
14
|
):
|
|
15
15
|
self.db_id, self.notion = db_id, notion
|
|
16
|
+
|
|
17
|
+
# Fetch and store the data source ID
|
|
18
|
+
db_info = self.notion.databases.retrieve(self.db_id)
|
|
19
|
+
self.data_source_id = db_info['data_sources'][0]['id']
|
|
16
20
|
|
|
17
21
|
def get_schema(self):
|
|
18
22
|
"""Retrieve the database schema.
|
|
@@ -22,6 +26,16 @@ class Database:
|
|
|
22
26
|
"""
|
|
23
27
|
db = self.notion.databases.retrieve(self.db_id)
|
|
24
28
|
return {name: props['type'] for name, props in db['properties'].items()}
|
|
29
|
+
|
|
30
|
+
def check_db_exists(self):
|
|
31
|
+
"Check if database exists and is accessible"
|
|
32
|
+
try:
|
|
33
|
+
db = self.notion.databases.retrieve(database_id=self.db_id)
|
|
34
|
+
print(f"✓ Database exists: {db['title'][0]['plain_text']}")
|
|
35
|
+
return True
|
|
36
|
+
except Exception as e:
|
|
37
|
+
print(f"✗ Database not found: {e}")
|
|
38
|
+
return False
|
|
25
39
|
|
|
26
40
|
# %% ../nbs/00_core.ipynb #52b04240
|
|
27
41
|
class TriggerDB(Database):
|
|
@@ -80,7 +94,7 @@ class JunctionDB(Database):
|
|
|
80
94
|
dict: Mapping of item IDs to their amounts, empty dict if no relation_id
|
|
81
95
|
"""
|
|
82
96
|
if not relation_id: return {}
|
|
83
|
-
res = self.notion.data_sources.query(data_source_id=self.
|
|
97
|
+
res = self.notion.data_sources.query(data_source_id=self.data_source_id, filter={"property": self.relation_prop, "relation": {"contains": relation_id}})
|
|
84
98
|
return {r['properties'][self.item_prop]['relation'][0]['id']: r['properties'][self.amount_prop]['number'] for r in res['results']}
|
|
85
99
|
|
|
86
100
|
#| export
|
|
@@ -133,13 +147,16 @@ class AutoLogger:
|
|
|
133
147
|
self.trigger_db, self.junction_db, self.log_db = trigger_db, junction_db, log_db
|
|
134
148
|
self.trigger_status, self.multiplier = trigger_status, multiplier
|
|
135
149
|
|
|
136
|
-
def process(self,
|
|
150
|
+
def process(self,
|
|
151
|
+
page_id,
|
|
152
|
+
reason:str # Reason for log entry
|
|
153
|
+
):
|
|
137
154
|
"""Process a trigger page and create log entries."""
|
|
138
155
|
status, relation_id, qty = self.trigger_db.get_page_data(page_id)
|
|
139
156
|
if status != self.trigger_status: return f"Status is {status}, not {self.trigger_status}"
|
|
140
157
|
items = self.junction_db.get_items(relation_id)
|
|
141
158
|
if not items: return "No items found in junction"
|
|
142
|
-
for item_id, amt in items.items(): self.log_db.create_entry(item_id, self.multiplier * qty * amt, page_id,
|
|
159
|
+
for item_id, amt in items.items(): self.log_db.create_entry(item_id, self.multiplier * qty * amt, page_id, reason)
|
|
143
160
|
return f"Logged {len(items)} items"
|
|
144
161
|
|
|
145
162
|
def cancel(self, page_id):
|
|
@@ -176,3 +193,4 @@ class AutoLogger:
|
|
|
176
193
|
if old_status and old_status != self.trigger_status: return self.process(page_id)
|
|
177
194
|
if old_qty and old_qty != qty: return self.adjust_batch(page_id, old_qty, qty)
|
|
178
195
|
return "No action needed"
|
|
196
|
+
|
{notion_cascade_insert-0.0.1 → notion_cascade_insert-0.0.3/notion_cascade_insert.egg-info}/PKG-INFO
RENAMED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: notion_cascade_insert
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.3
|
|
4
4
|
Summary: Cascade inserting for Notion Database Automation (as log)
|
|
5
5
|
Home-page: https://github.com/amezaikupan/notion_cascade_insert
|
|
6
|
-
Author:
|
|
7
|
-
Author-email:
|
|
6
|
+
Author: TN
|
|
7
|
+
Author-email: amezaikupan@gmail.com
|
|
8
8
|
License: Apache-2.0
|
|
9
9
|
Keywords: nbdev jupyter notebook python
|
|
10
10
|
Classifier: Development Status :: 4 - Beta
|
|
@@ -47,25 +47,6 @@ Dynamic: summary
|
|
|
47
47
|
! pip install notion_cascade_insert
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
-
Requirement already satisfied: notion_cascade_insert in /app/data/.local/lib/python3.12/site-packages (0.0.1)
|
|
51
|
-
Requirement already satisfied: fastcore in /usr/local/lib/python3.12/site-packages (from notion_cascade_insert) (1.12.2)
|
|
52
|
-
Requirement already satisfied: fastapi in /usr/local/lib/python3.12/site-packages (from notion_cascade_insert) (0.128.0)
|
|
53
|
-
Requirement already satisfied: notion_client in /app/data/.local/lib/python3.12/site-packages (from notion_cascade_insert) (2.7.0)
|
|
54
|
-
Requirement already satisfied: starlette<0.51.0,>=0.40.0 in /app/data/.local/lib/python3.12/site-packages (from fastapi->notion_cascade_insert) (0.50.0)
|
|
55
|
-
Requirement already satisfied: pydantic>=2.7.0 in /usr/local/lib/python3.12/site-packages (from fastapi->notion_cascade_insert) (2.12.5)
|
|
56
|
-
Requirement already satisfied: typing-extensions>=4.8.0 in /usr/local/lib/python3.12/site-packages (from fastapi->notion_cascade_insert) (4.15.0)
|
|
57
|
-
Requirement already satisfied: annotated-doc>=0.0.2 in /usr/local/lib/python3.12/site-packages (from fastapi->notion_cascade_insert) (0.0.4)
|
|
58
|
-
Requirement already satisfied: anyio<5,>=3.6.2 in /usr/local/lib/python3.12/site-packages (from starlette<0.51.0,>=0.40.0->fastapi->notion_cascade_insert) (4.12.1)
|
|
59
|
-
Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.12/site-packages (from anyio<5,>=3.6.2->starlette<0.51.0,>=0.40.0->fastapi->notion_cascade_insert) (3.11)
|
|
60
|
-
Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.12/site-packages (from pydantic>=2.7.0->fastapi->notion_cascade_insert) (0.7.0)
|
|
61
|
-
Requirement already satisfied: pydantic-core==2.41.5 in /usr/local/lib/python3.12/site-packages (from pydantic>=2.7.0->fastapi->notion_cascade_insert) (2.41.5)
|
|
62
|
-
Requirement already satisfied: typing-inspection>=0.4.2 in /usr/local/lib/python3.12/site-packages (from pydantic>=2.7.0->fastapi->notion_cascade_insert) (0.4.2)
|
|
63
|
-
Requirement already satisfied: packaging in /usr/local/lib/python3.12/site-packages (from fastcore->notion_cascade_insert) (25.0)
|
|
64
|
-
Requirement already satisfied: httpx>=0.23.0 in /usr/local/lib/python3.12/site-packages (from notion_client->notion_cascade_insert) (0.28.1)
|
|
65
|
-
Requirement already satisfied: certifi in /usr/local/lib/python3.12/site-packages (from httpx>=0.23.0->notion_client->notion_cascade_insert) (2026.1.4)
|
|
66
|
-
Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.12/site-packages (from httpx>=0.23.0->notion_client->notion_cascade_insert) (1.0.9)
|
|
67
|
-
Requirement already satisfied: h11>=0.16 in /usr/local/lib/python3.12/site-packages (from httpcore==1.*->httpx>=0.23.0->notion_client->notion_cascade_insert) (0.16.0)
|
|
68
|
-
|
|
69
50
|
## How to use
|
|
70
51
|
|
|
71
52
|
### Building blocks
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
### Python library ###
|
|
6
6
|
repo = notion_cascade_insert
|
|
7
7
|
lib_name = %(repo)s
|
|
8
|
-
version = 0.0.
|
|
8
|
+
version = 0.0.3
|
|
9
9
|
min_python = 3.9
|
|
10
10
|
license = apache2
|
|
11
11
|
black_formatting = False
|
|
@@ -29,8 +29,8 @@ title = %(lib_name)s
|
|
|
29
29
|
|
|
30
30
|
### PyPI ###
|
|
31
31
|
audience = Developers
|
|
32
|
-
author =
|
|
33
|
-
author_email =
|
|
32
|
+
author = TN
|
|
33
|
+
author_email = amezaikupan@gmail.com
|
|
34
34
|
copyright = 2026 onwards, %(author)s
|
|
35
35
|
description = Cascade inserting for Notion Database Automation (as log)
|
|
36
36
|
keywords = nbdev jupyter notebook python
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
# Notion Cascade Insert
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
|
|
5
|
-
|
|
6
|
-
## Installing
|
|
7
|
-
|
|
8
|
-
``` python
|
|
9
|
-
! pip install notion_cascade_insert
|
|
10
|
-
```
|
|
11
|
-
|
|
12
|
-
Requirement already satisfied: notion_cascade_insert in /app/data/.local/lib/python3.12/site-packages (0.0.1)
|
|
13
|
-
Requirement already satisfied: fastcore in /usr/local/lib/python3.12/site-packages (from notion_cascade_insert) (1.12.2)
|
|
14
|
-
Requirement already satisfied: fastapi in /usr/local/lib/python3.12/site-packages (from notion_cascade_insert) (0.128.0)
|
|
15
|
-
Requirement already satisfied: notion_client in /app/data/.local/lib/python3.12/site-packages (from notion_cascade_insert) (2.7.0)
|
|
16
|
-
Requirement already satisfied: starlette<0.51.0,>=0.40.0 in /app/data/.local/lib/python3.12/site-packages (from fastapi->notion_cascade_insert) (0.50.0)
|
|
17
|
-
Requirement already satisfied: pydantic>=2.7.0 in /usr/local/lib/python3.12/site-packages (from fastapi->notion_cascade_insert) (2.12.5)
|
|
18
|
-
Requirement already satisfied: typing-extensions>=4.8.0 in /usr/local/lib/python3.12/site-packages (from fastapi->notion_cascade_insert) (4.15.0)
|
|
19
|
-
Requirement already satisfied: annotated-doc>=0.0.2 in /usr/local/lib/python3.12/site-packages (from fastapi->notion_cascade_insert) (0.0.4)
|
|
20
|
-
Requirement already satisfied: anyio<5,>=3.6.2 in /usr/local/lib/python3.12/site-packages (from starlette<0.51.0,>=0.40.0->fastapi->notion_cascade_insert) (4.12.1)
|
|
21
|
-
Requirement already satisfied: idna>=2.8 in /usr/local/lib/python3.12/site-packages (from anyio<5,>=3.6.2->starlette<0.51.0,>=0.40.0->fastapi->notion_cascade_insert) (3.11)
|
|
22
|
-
Requirement already satisfied: annotated-types>=0.6.0 in /usr/local/lib/python3.12/site-packages (from pydantic>=2.7.0->fastapi->notion_cascade_insert) (0.7.0)
|
|
23
|
-
Requirement already satisfied: pydantic-core==2.41.5 in /usr/local/lib/python3.12/site-packages (from pydantic>=2.7.0->fastapi->notion_cascade_insert) (2.41.5)
|
|
24
|
-
Requirement already satisfied: typing-inspection>=0.4.2 in /usr/local/lib/python3.12/site-packages (from pydantic>=2.7.0->fastapi->notion_cascade_insert) (0.4.2)
|
|
25
|
-
Requirement already satisfied: packaging in /usr/local/lib/python3.12/site-packages (from fastcore->notion_cascade_insert) (25.0)
|
|
26
|
-
Requirement already satisfied: httpx>=0.23.0 in /usr/local/lib/python3.12/site-packages (from notion_client->notion_cascade_insert) (0.28.1)
|
|
27
|
-
Requirement already satisfied: certifi in /usr/local/lib/python3.12/site-packages (from httpx>=0.23.0->notion_client->notion_cascade_insert) (2026.1.4)
|
|
28
|
-
Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.12/site-packages (from httpx>=0.23.0->notion_client->notion_cascade_insert) (1.0.9)
|
|
29
|
-
Requirement already satisfied: h11>=0.16 in /usr/local/lib/python3.12/site-packages (from httpcore==1.*->httpx>=0.23.0->notion_client->notion_cascade_insert) (0.16.0)
|
|
30
|
-
|
|
31
|
-
## How to use
|
|
32
|
-
|
|
33
|
-
### Building blocks
|
|
34
|
-
|
|
35
|
-
This package is built to emulate the `Notion Automation` function but
|
|
36
|
-
with one to many relation. I built this to track the transactions (hence
|
|
37
|
-
the log) that involves calculating in case where there is an big object
|
|
38
|
-
that map to many other objects, like when you have a recipe and you want
|
|
39
|
-
to get the ingredients, or when you have a lists of guests and you want
|
|
40
|
-
to get their details… This helps you manage the ammoun of stuff that
|
|
41
|
-
relate to that big object.
|
|
42
|
-
|
|
43
|
-
There are 4 of the pipelines:
|
|
44
|
-
|
|
45
|
-
1. **TriggerDB**: monitors a database for status changes
|
|
46
|
-
2. **JunctionDB**: looks up related items and amounts
|
|
47
|
-
3. **LogDB**: writes transaction logs
|
|
48
|
-
4. **AutoLogger**: orchestrates the flow
|
|
49
|
-
|
|
50
|
-
We can than use them to connect to `Notion Webhook` and create the
|
|
51
|
-
functions that we want.
|
|
52
|
-
|
|
53
|
-
### Example
|
|
54
|
-
|
|
55
|
-
<!-- <img src="img/mermaid-diagram-2026-01-24-213107.png"> -->
|
|
56
|
-
|
|
57
|
-
<img src="img/mermaid-diagram-2026-01-24-213107.png" style="width: 100%; height: auto; max-height: none;">
|
|
58
|
-
|
|
59
|
-
Let’s say we’re building a Bakery Inventory management database, and we
|
|
60
|
-
want our `Production Plan` database to automatically log the used
|
|
61
|
-
ingredients in a recipe that we want to make. This is a one-to-many
|
|
62
|
-
behavior, which Notion don’t support at the momment. For this, we would
|
|
63
|
-
do something like:
|
|
64
|
-
|
|
65
|
-
``` python
|
|
66
|
-
from notion_cascade_insert.core import TriggerDB, JunctionDB, LogDB, AutoLogger
|
|
67
|
-
from notion_cascade_insert.webhook import NotionWebhook
|
|
68
|
-
from fastapi import FastAPI, Request
|
|
69
|
-
from notion_client import Client
|
|
70
|
-
import os
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
``` python
|
|
74
|
-
notion = Client(auth=os.getenv("NOTION_TOKEN"))
|
|
75
|
-
|
|
76
|
-
trigger = TriggerDB(os.getenv("PRODUCTION_PLAN_DB_ID"), notion, "Status", "Recipes", "Batches to make")
|
|
77
|
-
junction = JunctionDB(os.getenv("RECIPE_INGREDIENTS_DB_ID"), notion, "Recipes", "Ingredient Inventory", "Amount per batch")
|
|
78
|
-
log = LogDB(os.getenv("INGREDIENT_TRANSACTION_DB"), notion, "Ingredient", "Amount", "Production Plan", "Reason")
|
|
79
|
-
db_logger = AutoLogger(trigger, junction, log, "In Process", -1)
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
This will create your Ingredient Logger! Then you can set up your server
|
|
83
|
-
like so:
|
|
84
|
-
|
|
85
|
-
``` python
|
|
86
|
-
app = FastAPI()
|
|
87
|
-
|
|
88
|
-
@app.post("/webhook")
|
|
89
|
-
async def webhook(request: Request):
|
|
90
|
-
hook = NotionWebhook(await request.json())
|
|
91
|
-
if hook.parent_db_id == os.getenv("PRODUCTION_PLAN_DB_ID"):
|
|
92
|
-
if hook.type == 'page.created': return {"result": db_logger.process(hook.entity_id)}
|
|
93
|
-
return {"status": "received"}
|
|
94
|
-
```
|
|
File without changes
|
|
File without changes
|
{notion_cascade_insert-0.0.1 → notion_cascade_insert-0.0.3}/notion_cascade_insert/webhook.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|