Skip to main content

Cascade inserting for Notion Database Automation (as log)

Project description

Notion Cascade Insert

Installing

! pip install notion_cascade_insert

How to use

Building blocks

This package is built to emulate the Notion Automation function but with one to many relation. I built this to track the transactions (hence the log) that involves calculating in case where there is an big object that map to many other objects, like when you have a recipe and you want to get the ingredients, or when you have a lists of guests and you want to get their details… This helps you manage the ammoun of stuff that relate to that big object.

There are 4 of the pipelines:

  1. TriggerDB: monitors a database for status changes
  2. JunctionDB: looks up related items and amounts
  3. LogDB: writes transaction logs
  4. AutoLogger: orchestrates the flow

We can than use them to connect to Notion Webhook and create the functions that we want.

Example

Let’s say we’re building a Bakery Inventory management database, and we want our Production Plan database to automatically log the used ingredients in a recipe that we want to make. This is a one-to-many behavior, which Notion don’t support at the momment. For this, we would do something like:

from notion_cascade_insert.core import TriggerDB, JunctionDB, LogDB, AutoLogger
from notion_cascade_insert.webhook import NotionWebhook 
from fastapi import FastAPI, Request 
from notion_client import Client 
import os
notion = Client(auth=os.getenv("NOTION_TOKEN"))

trigger = TriggerDB(os.getenv("PRODUCTION_PLAN_DB_ID"), notion, "Status", "Recipes", "Batches to make")
junction = JunctionDB(os.getenv("RECIPE_INGREDIENTS_DB_ID"), notion, "Recipes", "Ingredient Inventory", "Amount per batch")
log = LogDB(os.getenv("INGREDIENT_TRANSACTION_DB"), notion, "Ingredient", "Amount", "Production Plan", "Reason")
db_logger = AutoLogger(trigger, junction, log, "In Process", -1)

This will create your Ingredient Logger! Then you can set up your server like so:

app = FastAPI()

@app.post("/webhook")
async def webhook(request: Request):
    hook = NotionWebhook(await request.json())
    if hook.parent_db_id == os.getenv("PRODUCTION_PLAN_DB_ID"):
        if hook.type == 'page.created': return {"result": db_logger.process(hook.entity_id)}
    return {"status": "received"}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

notion_cascade_insert-0.0.3.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

notion_cascade_insert-0.0.3-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file notion_cascade_insert-0.0.3.tar.gz.

File metadata

  • Download URL: notion_cascade_insert-0.0.3.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for notion_cascade_insert-0.0.3.tar.gz
Algorithm Hash digest
SHA256 f80aa08ac9fbc02278314fbbe40340ee7c260aaebba39857fcade7e529c0f8c3
MD5 e10627da250384415fdf8e98dec6d8ae
BLAKE2b-256 2d1d1b5a4e41ddca7f6be6b3f4026f216b55ed9156eb2c50af4dd423644942bb

See more details on using hashes here.

File details

Details for the file notion_cascade_insert-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for notion_cascade_insert-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 00cf5f15e721a07d0f989c1967b2a2fd60eb8c98a2059f967bcec44f02a73f8c
MD5 30caf64d5e0f9f49118e5b7c086e3dec
BLAKE2b-256 ae67b1b3669cc3befc70d8285b7d2f446369fe751cf439f089558f7f74e3e4f4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page