Skip to content

BlockNote-py - Python Library for BlockNote.js

PyPI version Python Support License: MIT

BlockNote-py is the official Python library for BlockNote.js, providing seamless integration and conversion between BlockNote blocks and various formats including HTML, Markdown, and Python dictionaries. Whether you're building a Python backend for a BlockNote editor or need to process BlockNote content server-side, BlockNote-py makes it simple and type-safe.

Why BlockNote-py?

BlockNote-py bridges the gap between JavaScript's BlockNote.js and Python applications, enabling you to:

  • Process BlockNote content in Python - Handle BlockNote blocks server-side
  • Convert between formats - Transform BlockNote to HTML, Markdown, or JSON
  • Type-safe operations - Built with Pydantic for robust validation
  • Server-side rendering - Generate HTML from BlockNote blocks for SEO
  • Content migration - Import/export content between different formats

โœจ Features

  • ๐Ÿ”„ Bidirectional Conversion: Convert between BlockNote blocks and multiple formats
  • ๐ŸŒ HTML Support: Full HTML conversion with styling preservation
  • ๐Ÿ“ Markdown Support: Convert to/from Markdown with formatting
  • ๐Ÿ“Š Dictionary Support: Work with BlockNote data as Python dictionaries
  • ๐ŸŽจ Rich Formatting: Support for bold, italic, colors, and more
  • ๐Ÿงช Type Safe: Built with Pydantic for robust type validation
  • ๐Ÿš€ Easy to Use: Simple, intuitive API

๐Ÿš€ Quick Start

Installation

pip install blocknote-py

Basic Usage

from blocknote.converter import blocks_to_html, html_to_blocks
from blocknote.schema import Block, InlineContent

# Create a BlockNote block
block = Block(
    id="1",
    type="paragraph",
    content=[
        InlineContent(
            type="text", 
            text="Hello, World!", 
            styles={"bold": True}
        )
    ]
)

# Convert to HTML
html = blocks_to_html([block])
print(html)  # <p><strong>Hello, World!</strong></p>

# Convert back to BlockNote
blocks = html_to_blocks(html)
print(blocks[0].content[0].text)  # Hello, World!

๐Ÿ”ง Supported Conversions

From/To HTML Markdown Dictionary
BlockNote โœ… โœ… โœ…
HTML - โŒ โŒ
Markdown โŒ - โŒ
Dictionary โŒ โŒ -

๐Ÿ“š Documentation

โ“ Frequently Asked Questions

What is the BlockNote Python library?

BlockNote-py is the Python companion to BlockNote.js. It ships Pydantic models and converter utilities so that any Python project can read and write BlockNote documents, making it ideal for FastAPI, Django, Flask, and other backend frameworks.

How do I install BlockNote-py with PDF export capability?

Use the optional PDF extra when installing from PyPI:

pip install "blocknote-py[pdf]"

This installs WeasyPrint alongside the core BlockNote Python tooling so you can render BlockNote pages as PDFs on the server.

Does BlockNote-py support SEO-friendly HTML rendering?

Yes. The blocks_to_html converter produces semantic HTML that you can serve directly to crawlers. Pair it with the provided styling to generate markup that search engines can index, helping BlockNote-driven sites rank for their content.

๐Ÿค Contributing

We welcome contributions! Please see our Contributing Guide for details.

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

โ˜• Support the Project

If you find BlockNote-py useful, consider supporting its development:

Buy Me A Coffee

Your support helps maintain and improve BlockNote-py for the entire Python community! ๐Ÿ™

๐Ÿ™ Acknowledgments

  • BlockNote.js - The amazing block-based editor that inspired this library
  • Pydantic - For robust data validation