Skip to content

adamtheturtle/sphinx-notionbuilder

Repository files navigation

Build Status PyPI

Builder for Sphinx which enables publishing documentation to Notion.

See a sample document source and the published Notion page for an example of what it can do.

sphinx-notionbuilder is compatible with Python 3.11+.

$ pip install sphinx-notionbuilder

Add the following to conf.py to enable the extension:

"""Configuration for Sphinx."""

extensions = ["sphinx_notion"]

sphinx-notionbuilder also works with a variety of Sphinx extensions:

See a sample document source and the published Notion page for an example of each of these.

To set these up, install the extensions you want to use and add them to your conf.py, before sphinx_notion:

"""Configuration for Sphinx."""

extensions = [
    "atsphinx.audioplayer",
    "sphinx.ext.mathjax",
    "sphinx_iframes",
    "sphinx_immaterial.task_lists",
    "sphinx_simplepdf",
    "sphinx_toolbox.collapse",
    "sphinx_toolbox.rest_example",
    "sphinxcontrib.video",
    "sphinxcontrib_text_styles",
    "sphinxnotes.strike",
    "sphinx_notion",
]

The following syntax is supported:

  • Headers
  • Bulleted lists
  • TODO lists (with checkboxes)
  • Code blocks
  • Table of contents
  • Block quotes
  • Callouts
  • Collapsible sections (using the collapse directive from sphinx-toolbox )
  • Rest-example blocks (using the rest-example directive from sphinx-toolbox )
  • Images (with URLs or local paths)
  • Videos (with URLs or local paths)
  • Audio (with URLs or local paths)
  • PDFs (with URLs or local paths)
  • Embed blocks (using the iframe directive from sphinx-iframes )
  • Tables
  • Dividers (horizontal rules / transitions)
  • Strikethrough text (using the strike role from sphinxnotes-strike )
  • Colored text and text styles (bold, italic, monospace) (using various roles from sphinxcontrib-text-styles )
  • Mathematical equations (inline and block-level, using the math role and directive from sphinx.ext.mathjax )
  • Link to page blocks (using the notion-link-to-page directive)
  • Mentions (users, pages, databases, dates) (using the notion-mention-user, notion-mention-page, notion-mention-database, and notion-mention-date roles)

See a sample document source and the published Notion page.

All of these can be used in a way which means your documentation can still be rendered to HTML.

sphinx-notionbuilder provides custom directives for Notion-specific features:

Creates a Notion "link to page" block that references another page in your Notion workspace.

Usage:

.. notion-link-to-page:: PAGE_ID

Parameters:

  • PAGE_ID: The UUID of the Notion page you want to link to (without hyphens or with hyphens, both formats are accepted)

Example:

.. notion-link-to-page:: 12345678-1234-1234-1234-123456789abc

This creates a clickable link block in Notion that navigates to the specified page when clicked.

sphinx-notionbuilder provides custom roles for inline Notion-specific features:

Creates a Notion user mention inline.

Usage:

:notion-mention-user:`USER_ID`

Parameters:

  • USER_ID: The UUID of the Notion user you want to mention

Example:

Hello :notion-mention-user:`12345678-1234-1234-1234-123456789abc` there!

Creates a Notion page mention inline.

Usage:

:notion-mention-page:`PAGE_ID`

Parameters:

  • PAGE_ID: The UUID of the Notion page you want to mention

Example:

See :notion-mention-page:`87654321-4321-4321-4321-cba987654321` for details.

Creates a Notion database mention inline.

Usage:

:notion-mention-database:`DATABASE_ID`

Parameters:

  • DATABASE_ID: The UUID of the Notion database you want to mention

Example:

Check the :notion-mention-database:`abcdef12-3456-7890-abcd-ef1234567890` database.

Creates a Notion date mention inline.

Usage:

:notion-mention-date:`DATE_STRING`

Parameters:

  • DATE_STRING: A date string in ISO format (e.g., 2025-11-09)

Example:

The meeting is on :notion-mention-date:`2025-11-09`.
  • Bookmark
  • Breadcrumb
  • Child database
  • Child page
  • Column and column list
  • File
  • Link preview
  • Synced block
  • Template
  • Heading with is_toggleable set to True

Build documentation with the notion builder. For eaxmple:

$ sphinx-build -W -b notion source build/notion

After building your documentation with the Notion builder, you can upload it to Notion using the included command-line tool.

  1. Create a Notion integration at notion-integrations

The integration token must have the following "Capabilities" set within the "Configuration" tab:

  • Content Capabilities: Insert content, Update content, Read content
  • Comment Capabilities: Read comments (required for checking if blocks have discussion threads for the --cancel-on-discussion option)
  • User Capabilities: Read user information without email addresses (for bot identification)

In the "Access" tab, choose the pages and databases your integration can access.

  1. Get your integration token and set it as an environment variable:
$ export NOTION_TOKEN="your_integration_token_here"
# The JSON file will be in the build directory, e.g. ./build/notion/index.json
$ notion-upload --file path/to/output.json --parent-page-id parent_page_id --title "Page Title"

Or with a database parent:

$ notion-upload --file path/to/output.json --parent-database-id parent_database_id --title "Page Title"

Arguments:

  • --file: Path to the JSON file generated by the Notion builder
  • --parent-page-id: The ID of the parent page in Notion (must be shared with your integration) - mutually exclusive with --parent-database-id
  • --parent-database-id: The ID of the parent database in Notion (must be shared with your integration) - mutually exclusive with --parent-page-id
  • --title: Title for the new page in Notion
  • --icon: (Optional) Icon for the page (emoji)
  • --cover-path: (Optional) Path to a cover image file for the page

The command will create a new page if one with the given title doesn't exist, or update the existing page if one with the given title already exists.

About

Sphinx builder for Notion

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages