Skip to content

rohansharmasitoula/blocknote-py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

25 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

BlockNote-py πŸš€ - BlockNote Python Library

PyPI version Python Support License: MIT Documentation CI PyPI - Downloads GitHub stars

🎯 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.

πŸ€” Why BlockNote-py?

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.

🎯 Perfect For:

  • 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

✨ Features

  • πŸ”„ 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

πŸ“¦ Installation

Basic Installation

pip install blocknote-py

With PDF Support

pip install 'blocknote-py[pdf]'

Full Installation (all features)

pip install 'blocknote-py[all]'

πŸš€ Quick Start

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)

πŸ“š Documentation

Complete documentation: https://rohansharmasitoula.github.io/blocknote-py/

Quick Navigation

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

❓ Frequently Asked Questions

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.

🀝 Contributing

Contributions are welcome! 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


⭐ Star this repo if you find it useful!

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors