Classes
NotionSource
Content source for Notion databases.
Fetches pages from a Notion database and converts them to mar…
NotionSource
Content source for Notion databases.
Fetches pages from a Notion database and converts them to markdown. Requires a Notion integration token with read access to the database.
Configuration:
database_id: str - Notion database ID (required)
token: str - Notion integration token (or NOTION_TOKEN env var)
property_mapping: dict - Map Notion properties to frontmatter fields
Defaults: {"title": "Name", "date": "Date", "tags": "Tags"}
filter: dict - Notion filter object (optional)
sorts: list - Notion sorts array (optional)
Setup:
1. Create a Notion integration at https://www.notion.so/my-integrations
2. Share your database with the integration
3. Set NOTION_TOKEN environment variable or pass token in config
ContentSourceMethods 2
fetch_all
async
Fetch all pages from the database.
Handles pagination automatically.
fetch_all
async async def fetch_all(self) -> AsyncIterator[ContentEntry]
Fetch all pages from the database.
Handles pagination automatically.
Returns
AsyncIterator[ContentEntry]
fetch_one
async
Fetch a single page by ID.
fetch_one
async async def fetch_one(self, id: str) -> ContentEntry | None
Fetch a single page by ID.
Parameters 1
id |
str |
Notion page ID |
Returns
ContentEntry if found, None otherwiseContentEntry | None
—
Internal Methods 7
__init__
Initialize Notion source.
__init__
def __init__(self, name: str, config: dict[str, Any]) -> None
Initialize Notion source.
Parameters 2
name |
str |
Source name |
config |
dict[str, Any] |
Configuration with 'database_id' required |
_page_to_entry
async
Convert Notion page to ContentEntry.
_page_to_entry
async async def _page_to_entry(self, session: aiohttp.ClientSession, page: dict[str, Any]) -> ContentEntry | None
Convert Notion page to ContentEntry.
Parameters 2
session |
aiohttp.ClientSession |
aiohttp session |
page |
dict[str, Any] |
Notion page object |
Returns
ContentEntry or NoneContentEntry | None
—
_get_page_content
async
Fetch and convert page blocks to markdown.
_get_page_content
async async def _get_page_content(self, session: aiohttp.ClientSession, page_id: str) -> str
Fetch and convert page blocks to markdown.
Parameters 2
session |
aiohttp.ClientSession |
aiohttp session |
page_id |
str |
Notion page ID |
Returns
Markdown content stringstr
—
_blocks_to_markdown
Convert Notion blocks to markdown.
_blocks_to_markdown
def _blocks_to_markdown(self, blocks: list[dict[str, Any]]) -> str
Convert Notion blocks to markdown.
Parameters 1
blocks |
list[dict[str, Any]] |
List of Notion block objects |
Returns
Markdown stringstr
—
_rich_text_to_md
Convert Notion rich text to markdown.
_rich_text_to_md
def _rich_text_to_md(self, rich_text: list[dict[str, Any]]) -> str
Convert Notion rich text to markdown.
Parameters 1
rich_text |
list[dict[str, Any]] |
List of rich text objects |
Returns
Markdown stringstr
—
_extract_properties
Extract Notion properties as frontmatter.
_extract_properties
def _extract_properties(self, page: dict[str, Any]) -> dict[str, Any]
Extract Notion properties as frontmatter.
Parameters 1
page |
dict[str, Any] |
Notion page object |
Returns
Frontmatter dictionarydict[str, Any]
—
_title_to_slug
Convert title to URL-friendly slug.
_title_to_slug
def _title_to_slug(self, title: str) -> str
Convert title to URL-friendly slug.
Parameters 1
title |
str |
Page title |
Returns
URL-friendly slugstr
—