Skip to main content

LangChain tools for read/write access to Notion via the official API.

Project description

LangChain Notion Tools

PyPI Build Coverage License Docs

LangChain Notion Tools is an external integration package that gives LangChain agents read and write access to Notion via the official Notion API. Built for the LangChain documentation ecosystem, it ships a polished developer experience:

  • 🔍 NotionSearchTool for locating pages and databases with LLM-friendly output.
  • ✍️ NotionWriteTool for creating and updating pages with rich blocks, property updates, and dry-run previews.
  • 🧱 Block helper utilities and a Markdown-to-Notion converter (from_text) to keep prompts terse.
  • 🛠️ A tiny CLI (notion-search, notion-write) to debug flows without leaving the terminal.
  • 📚 MkDocs-based documentation with doctested examples and JSON schemas ready for tool-calling LLMs.

Status: Actively developed. Contributions and feedback are welcome!


Installation

pip install langchain-notion-tools

Developers can install with extras for linting, typing, and doctests:

pip install -e .[dev]

Supported block helpers

Helper Block type Description
paragraph(text) paragraph Standard rich-text paragraph
heading_1/2/3(text) heading_1/2/3 Headings with descending emphasis
bulleted_list_item(text) bulleted_list_item Bulleted list entries
numbered_list_item(text) numbered_list_item Ordered list entries
to_do(text, checked=False) to_do Task items with optional checkbox
toggle(text, children=None) toggle Collapsible toggles with nested blocks
callout(text, icon=None) callout Callouts with optional icon metadata
quote(text) quote Quoted text blocks
code(text, language="plain text") code Code fences with link stripping

Use sanitize_blocks to enforce allowlists and size limits before sending content to Notion. The from_text helper converts a Markdown-like syntax (#, -, 1., ``` fences) into a safe block payload.


Quickstart

from langchain_notion_tools import NotionSearchTool, NotionWriteTool, from_text

search = NotionSearchTool()
write = NotionWriteTool()

results = search.run(query="product roadmap")
print(results[0]["title"], results[0]["url"])

summary_blocks = from_text("### Summary\n- Release is on track\n- Risks reviewed")
response = write.run(
    update={"page_id": results[0]["id"], "mode": "append"},
    blocks=summary_blocks,
)
print(response["summary"])

Credentials are read from NOTION_API_TOKEN (and optionally NOTION_DEFAULT_PARENT_PAGE_ID). See docs/quickstart.md for full setup instructions, including CLI usage.


Toolkit helper

When you need both tools side by side, use the NotionToolkit factory. It shares a single Notion client across the search and write tools so rate limits and retries are coordinated.

from langchain_notion_tools import create_toolkit

notion = create_toolkit()
for tool in notion.tools:
    print(tool.name)

# Plug into an agent
from langchain_core.runnables import RunnableParallel
workflow = RunnableParallel({"search": notion.search, "write": notion.write})

Call create_toolkit(api_token="...") to override credentials or pass an existing NotionClientSettings instance.


CLI

Debug workflows without writing a script:

# Search for specs
notion-search --query "api spec" --limit 5

# Append Markdown-converted blocks to a page
notion-write --update-page "abcd1234" --blocks-from-text "### Decisions\n- Adopt OAuth2"

# Create a page in the default parent and dry-run the payload
notion-write --title "Weekly Review" --blocks-from-text "# Intro" --dry-run

The CLI respects the same environment variables as the Python API and prints JSON responses that can be piped into jq for terminal-friendly inspection.


Documentation

The full documentation (Quickstart, Configuration, Examples, JSON Schema) lives under docs/ and is built with MkDocs Material:

pip install -e .[dev] mkdocs-material
mkdocs serve

Open http://127.0.0.1:8000 to browse the live docs with hot reload.


Examples

The examples/ directory contains runnable scripts and notebooks. They load .env files for convenience and show how to orchestrate read/write cycles, LangChain agents, and CLI automation.


Contributing

We follow Conventional Commits, run ruff, mypy, and pytest in CI, and welcome issues or pull requests. See CONTRIBUTING.md for the full guide.


License

This project is licensed under the MIT License. See LICENSE for details.

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

langchain_notion_tools-0.1.0.tar.gz (26.7 kB view details)

Uploaded Source

Built Distribution

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

langchain_notion_tools-0.1.0-py3-none-any.whl (27.9 kB view details)

Uploaded Python 3

File details

Details for the file langchain_notion_tools-0.1.0.tar.gz.

File metadata

  • Download URL: langchain_notion_tools-0.1.0.tar.gz
  • Upload date:
  • Size: 26.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for langchain_notion_tools-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c05bde036c9cde4eef83bcc2351a56b6be57026d4158002b7fc34979e3244e34
MD5 675ea6f799fe7c38b4bd2c79f2766733
BLAKE2b-256 3642ebc31be9bef7c62cef149ab9ec67fb237344029caec0dea1d42082a0b68f

See more details on using hashes here.

File details

Details for the file langchain_notion_tools-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_notion_tools-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 478db122959fa9a9fc248801fcd21761631f75a20fc62479094c13d92eb3654a
MD5 21bec3dd94fbe4e223b723c2564586c8
BLAKE2b-256 8568052e45b632092df623817f6c289d6b29e1bb3a86c85bc784f3f3297130a4

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