DEV Community

Jeremy Reevese
Jeremy Reevese

Posted on

How I Sync Notion CSV Using Python (Beginner-Friendly)

Notion is a great place to organize information, but sometimes you need your data in a real file — especially when working with spreadsheets, dashboards, BI tools, or automation workflows.

In this post, I’ll show you how to build a simple Python script that fetches data from a Notion database and writes it into a CSV file.

This is a beginner-friendly example, perfect for anyone learning:

  • Python data handling
  • Notion API basics
  • Automation workflows
  • One-person company internal tooling

Let’s keep it small, simple, and practical.


🚀 What We’re Building

A script that:

  • Connects to your Notion API
  • Fetches all rows from a Notion database
  • Converts them into Python objects
  • Writes the results into a CSV file
  • Runs in under 1 second

No frameworks.

Just requests + csv + a few lines of code.


📦 Requirements

You'll need:

  • A Notion API integration
  • A shared database
  • Your NOTION_API_KEY
  • The database ID
  • Python 3.8+

Install the only dependency:

pip install requests

Enter fullscreen mode Exit fullscreen mode

🧪 Minimal Working Code Example

Create a file named notion_to_csv.py:

import requests
import csv

NOTION_API_KEY = "YOUR_NOTION_SECRET_KEY"
DATABASE_ID = "YOUR_DATABASE_ID"

headers = {
    "Authorization": f"Bearer {NOTION_API_KEY}",
    "Notion-Version": "2022-06-28",
    "Content-Type": "application/json"
}

def fetch_notion_rows():
    url = f"https://api.notion.com/v1/databases/{DATABASE_ID}/query"
    response = requests.post(url, headers=headers)

    if response.status_code != 200:
        print("Error fetching data:", response.text)
        return []

    return response.json().get("results", [])

def parse_row(row):
    props = row["properties"]
    return {
        "Title": props["Name"]["title"][0]["plain_text"] if props["Name"]["title"] else "",
        "Status": props["Status"]["select"]["name"] if props["Status"]["select"] else "",
        "Created": row["created_time"]
    }

def write_csv(rows):
    with open("notion_export.csv", "w", newline="", encoding="utf-8") as f:
        writer = csv.DictWriter(f, fieldnames=["Title", "Status", "Created"])
        writer.writeheader()
        writer.writerows(rows)

def sync_notion_to_csv():
    raw_rows = fetch_notion_rows()
    parsed_rows = [parse_row(r) for r in raw_rows]
    write_csv(parsed_rows)
    print("CSV export completed → notion_export.csv")

if __name__ == "__main__":
    sync_notion_to_csv()

Enter fullscreen mode Exit fullscreen mode

📝 How It Works

1️⃣ Fetch Notion rows

We use /databases/{id}/query to pull entries.

2️⃣ Parse Notion properties

Notion stores data in nested structures — we extract:

  • Name
  • Status
  • Created time

(You can customize this for your own database.)

3️⃣ Write to CSV

Python’s built-in csv module handles everything.


📄 Output Example (notion_export.csv)

Title,Status,Created
Daily Report,Done,2025-01-02T10:12:00Z
Project Setup,In Progress,2025-01-05T14:09:22Z
Idea Notes,Backlog,2025-01-08T09:41:03Z

Enter fullscreen mode Exit fullscreen mode

Runs instantly → produces a clean structured CSV.


🧩 Why This Script Is Useful

This tiny tool is perfect for:

  • Migrating Notion content to other tools
  • Exporting weekly or monthly reports
  • Syncing data with Excel / Google Sheets
  • Feeding data into BI tools
  • Automating one-person company dashboards
  • Combining with n8n / Make workflows

You can even trigger this script daily via:

  • GitHub Actions
  • cron jobs
  • n8n “Execute Command” node
  • Make.com shell command module

Small script → real automation value.


📚 Full Repo Coming Soon

I'll publish a full “Notion → CSV Toolkit” on GitHub with:

  • Pagination
  • Rich text handling
  • Multi-select support
  • Date formatting
  • Deployment options

👉 (GitHub link placeholder — to be added)


💬 Want More?

Let me know if you'd like tutorials on:

  • Sync Notion ↔ Google Sheets
  • Notion API + FastAPI microservices
  • Notion → JSON pipelines
  • n8n workflows using Notion
  • Building a one-person company automation layer

Thanks for reading — and happy building! 🚀

Top comments (0)