Skip to main content

🚀 BlockNote Python library - Convert BlockNote.js blocks to HTML, Markdown, PDF & JSON. Type-safe Pydantic models for Django, FastAPI, Flask backends. Rich text editor content processing made easy.

Project description

BlockNote-py 🚀 - BlockNote Python Library

PyPI version Python Support License: MIT Documentation CI Downloads 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!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

blocknote_py-0.3.1.tar.gz (190.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

blocknote_py-0.3.1-py3-none-any.whl (53.2 kB view details)

Uploaded Python 3

File details

Details for the file blocknote_py-0.3.1.tar.gz.

File metadata

  • Download URL: blocknote_py-0.3.1.tar.gz
  • Upload date:
  • Size: 190.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.5

File hashes

Hashes for blocknote_py-0.3.1.tar.gz
Algorithm Hash digest
SHA256 cc3ad3f82ea277accf8348ce7630db09826d4ac3034431c6b49d5a9d7c419cd9
MD5 040611f05e5a71b6a53a710b11d39150
BLAKE2b-256 ed40c6fb32517bd3f7fd3cb095e9fb58c97249926240908424f3186b30dc8afd

See more details on using hashes here.

File details

Details for the file blocknote_py-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for blocknote_py-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6dd7df7ce1581d88590c173d9733ca5eb8ad7427b443dbf4e8f801cb7fd91786
MD5 d3dcb721e515960426aca1b8a3fee080
BLAKE2b-256 2639a274c395a3ec618ffaacaabdbdc4f3912eba06210e2647e74214965c6cc5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page