π― BlockNote Python Library - Convert BlockNote.js blocks to HTML, Markdown, PDF & JSON with type-safe Pydantic models. Perfect for Django, FastAPI, Flask backends and headless CMS applications. Server-side BlockNote content processing made simple.
BlockNote-py is the missing piece for Python developers who want to work with BlockNote.js content on the server-side. Whether you're building a Django blog, FastAPI content API, or Flask CMS, BlockNote-py provides seamless integration with Python backends.
- Django Developers: Process BlockNote content in Django models and views
- FastAPI APIs: Build content APIs with automatic validation and serialization
- Flask Applications: Add rich text processing to Flask apps
- Headless CMS: Convert editor content to multiple formats
- Content Migration: Batch process and convert existing content
- PDF Reports: Generate professional documents from editor content
- π Multiple Format Support: HTML, Markdown, PDF, and Dictionary conversion
- π HTML Conversion: Full bidirectional HTML support with styling preservation
- π Markdown Support: Convert to/from Markdown with formatting
- π PDF Generation: Convert BlockNote blocks to professional PDF documents with WeasyPrint
- π‘οΈ Type Safety: Built with Pydantic v2 for robust data validation and IDE support
- π¨ Rich Formatting: Bold, italic, colors, lists, quotes, headings, and more
- π§ͺ Well Tested: Comprehensive test suite with 88+ tests and 95% coverage
- π Great Documentation: Detailed docs with real-world examples
- β‘ Fast & Lightweight: Minimal dependencies, maximum performance
- π§ Framework Agnostic: Works with any Python web framework
pip install blocknote-pypip install 'blocknote-py[pdf]'pip install 'blocknote-py[all]'from blocknote.converter import blocks_to_html, blocks_to_markdown, blocks_to_pdf
from blocknote.schema import Block, InlineContent
# Create BlockNote blocks
blocks = [
Block(
id="1",
type="heading",
props={"level": 1},
content=[InlineContent(type="text", text="Welcome to BlockNote-py!")]
),
Block(
id="2",
type="paragraph",
content=[
InlineContent(type="text", text="Convert your "),
InlineContent(type="text", text="BlockNote", styles={"bold": True}),
InlineContent(type="text", text=" content to multiple formats!")
]
)
]
# Convert to different formats
html_output = blocks_to_html(blocks)
markdown_output = blocks_to_markdown(blocks)
pdf_bytes = blocks_to_pdf(blocks) # Requires PDF support
print("HTML:", html_output)
print("Markdown:", markdown_output)Complete documentation: https://rohansharmasitoula.github.io/blocknote-py/
| Section | Description |
|---|---|
| π Quick Start | Get up and running in minutes |
| π§ API Reference | Complete API documentation |
| π Converters | Detailed converter documentation |
| π‘ Examples | Real-world usage examples |
| π€ Contributing | How to contribute |
What is BlockNote-py?
BlockNote-py is the official BlockNote Python library that mirrors the data
model used by BlockNote.js. It lets Python
developers convert BlockNote content to HTML, Markdown, PDF, and JSON without
needing Node.js on the server.
How do I install the BlockNote Python package with PDF support?
Install the PyPI package with the optional PDF extra: pip install 'blocknote-py[pdf]'. This pulls in WeasyPrint so you can generate print-ready
PDF documents from BlockNote blocks.
Can I use BlockNote-py on the backend of a Django or FastAPI project?
Yes. BlockNote-py is framework-agnostic and works in any Python backend. The
package is typed with Pydantic models, making it easy to validate incoming
BlockNote payloads in Django REST Framework, FastAPI, Flask, or any custom API.
Does BlockNote-py stay in sync with BlockNote.js?
The converter and schema modules track the BlockNote.js block schema. Whenever
BlockNote introduces new block types or inline styles, BlockNote-py updates aim
to follow quickly so Python projects stay compatible.
Contributions are welcome! Please see our Contributing Guide for details.
This project is licensed under the MIT License - see the LICENSE file for details.
If you find BlockNote-py useful, consider supporting its development:
Your support helps maintain and improve BlockNote-py for the entire Python community! π
- BlockNote.js - The amazing block-based editor
- Pydantic - For robust data validation
β Star this repo if you find it useful!