Ever wished you could just type a prompt like "summarize this meeting" or "write an intro for my blog" and have it magically turn into a formatted note in your Notion workspace?

Well, now you can — and all it takes is a bit of Python and some help from OpenAI’s powerful API.

Whether you’re an automation nerd, a productivity freak, or just someone tired of copying and pasting between apps, this guide will show you step-by-step how to:

  • Connect Python to Notion
  • Connect Python to OpenAI’s API
  • Write a script where users can type a prompt → get a clean, AI-generated note in Notion

Let’s dive in.


🧠 What We’re Building

By the end of this post, you’ll have a working Python script that does the following:

✅ Takes a prompt from the user

✅ Sends it to OpenAI (GPT-4 or GPT-3.5)

✅ Gets back a response

✅ Automatically creates a formatted page in your Notion workspace

No manual writing. No toggling between tabs. Pure automation bliss.


🧰 Step 1: Prerequisites

To follow along, you’ll need:

Let’s go through it all step by step.


🛠️ Step 2: Set Up Your Notion Integration

This only takes a few minutes, but it's important.

✅ Create a Notion Integration

  1. Go to https://www.notion.com/my-integrations
  2. Click "New Integration"
  3. Give it a name like Note Generator
  4. Set the workspace where you want it to work
  5. Give it read and write permissions
  6. Copy your Internal Integration Token

🧠 Keep this token safe — we’ll use it later in the script.

✅ Share a Notion Page with Your Integration

You now need to give your integration access to a specific Notion page or database.

  1. Open the page or database you want to use
  2. Click Share > Invite
  3. Search for your integration’s name and invite it

Bonus tip: Use a Notion database if you want to store many notes in an organized way. Otherwise, you can just use a blank page.


⚙️ Step 3: Set Up Your Environment

Let’s install a few Python packages.

pip install openai notion-client python-dotenv

Then create a .env file in the same folder as your script:

OPENAI_API_KEY=your_openai_api_key_here
NOTION_TOKEN=your_notion_integration_token_here
NOTION_PAGE_ID=your_notion_page_or_database_id

If you’re not sure how to get the Notion page ID, open the page in your browser — it’s the weird string in the URL:

https://www.notion.so/yourworkspace/Page-Name-**c3c2e5fd123f46f987e813b8b93e8e38**

🧪 Step 4: The Python Script

Here’s a complete, clean script to generate notes.

import os
import openai
from notion_client import Client
from dotenv import load_dotenv

# Load your API keys from .env
load_dotenv()

openai.api_key = os.getenv("OPENAI_API_KEY")
notion_token = os.getenv("NOTION_TOKEN")
notion_page_id = os.getenv("NOTION_PAGE_ID")

# Set up Notion client
notion = Client(auth=notion_token)

# 1. Ask user for a prompt
prompt = input("What would you like your note to be about? ")

# 2. Send to OpenAI
print("Generating content with GPT...")
response = openai.ChatCompletion.create(
    model="gpt-4",  # or "gpt-3.5-turbo"
    messages=[
        {"role": "user", "content": prompt}
    ]
)
note_content = response["choices"][0]["message"]["content"]

# 3. Create the Notion page
print("Sending note to Notion...")

notion.pages.create(
    parent={"page_id": notion_page_id},
    properties={
        "title": [
            {
                "type": "text",
                "text": {
                    "content": prompt[:40] + "..."
                }
            }
        ]
    },
    children=[
        {
            "object": "block",
            "type": "paragraph",
            "paragraph": {
                "rich_text": [{
                    "type": "text",
                    "text": {"content": note_content}
                }]
            }
        }
    ]
)

print("✅ Note successfully created in Notion!")

💡 Example in Action

Let’s say you run this script and type:

Prompt: Write a bullet-point summary of the book Atomic Habits

GPT will generate a concise summary. Then, the script will:

  • Create a new page in your Notion workspace
  • Title it based on your prompt
  • Fill it with GPT’s magic

No copy-pasting. Just productivity, upgraded.


🚀 Next Steps

Once you’ve got the basics down, you can:

  • Accept more structured input (e.g. tags, tone, or note format)
  • Use Notion databases instead of pages for better organization
  • Build a simple web interface using Streamlit or Flask
  • Share it with your team or followers!

🎁 Final Thoughts

Notion + Python + OpenAI is an absolute dream combo for anyone into productivity, automation, or AI experiments. With just a few lines of code, you’ve created a custom notes assistant that speaks your language and keeps your second brain organized.

Imagine how much time you’ll save by automating daily journaling, meeting notes, or blog drafts.

You’re not just writing code — you’re building workflows your future self will thank you for.


If you'd like this whole setup turned into a ready-to-clone GitHub repo (with .env, readme, and maybe a Streamlit UI), just say the word.

From: - AlexGutts