Notion Is Not Just a Note App
Notion API lets you programmatically read, create, and update pages, databases, and blocks. Free for personal use, included in all plans.
Setup
- Go to notion.so/my-integrations
- Create new integration
- Copy the API key
- Share your database/page with the integration
import requests
TOKEN = "your_notion_api_key"
HEADERS = {
"Authorization": f"Bearer {TOKEN}",
"Content-Type": "application/json",
"Notion-Version": "2022-06-28"
}
Query a Database
def query_database(db_id, filter_obj=None):
data = {}
if filter_obj:
data["filter"] = filter_obj
r = requests.post(f"https://api.notion.com/v1/databases/{db_id}/query",
headers=HEADERS, json=data)
results = r.json()["results"]
return [{"id": p["id"], "props": {k: v for k, v in p["properties"].items()}}
for p in results]
# Get all items where Status = "Done"
items = query_database("your_db_id", {
"property": "Status",
"status": {"equals": "Done"}
})
Create a Page
def create_page(db_id, title, status="Not started"):
data = {
"parent": {"database_id": db_id},
"properties": {
"Name": {"title": [{"text": {"content": title}}]},
"Status": {"status": {"name": status}}
}
}
r = requests.post("https://api.notion.com/v1/pages",
headers=HEADERS, json=data)
return r.json()["id"]
page_id = create_page("db_id", "New task from Python")
Add Content to a Page
def add_blocks(page_id, blocks):
r = requests.patch(f"https://api.notion.com/v1/blocks/{page_id}/children",
headers=HEADERS, json={"children": blocks})
return r.json()
add_blocks(page_id, [
{"type": "heading_2", "heading_2": {
"rich_text": [{"text": {"content": "Summary"}}]
}},
{"type": "paragraph", "paragraph": {
"rich_text": [{"text": {"content": "This was created via the API."}}]
}},
{"type": "bulleted_list_item", "bulleted_list_item": {
"rich_text": [{"text": {"content": "First point"}}]
}}
])
Real Automation Ideas
- Daily standup bot — create a page every morning with template
- CRM — add leads from email/forms directly to Notion database
- Content calendar — sync Dev.to articles to Notion tracker
- Project dashboard — aggregate data from multiple databases
- Meeting notes — auto-create pages with attendees and agenda
Rate Limits
- 3 requests per second per integration
- No daily limit
- Pagination for large databases (100 items per page)
Need custom dev tools, scrapers, or API integrations? I build automation for dev teams. Email spinov001@gmail.com — or explore awesome-web-scraping.
More from me: 10 Dev Tools I Use Daily | 77 Scrapers on a Schedule | 150+ Free APIs
NEW: I Ran an AI Agent for 16 Days — What Works
Top comments (0)