BlockNote-py - Python Library for BlockNote.js¶
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¶
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¶
- Getting Started - Installation and setup
- Converters - Detailed converter documentation
- API Reference - Complete API documentation
- Examples - Practical examples and use cases
โ 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:
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:
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