skillfed

draftjs_exporter

Library to convert rich text from Draft.js raw ContentState to HTML

draftjs-exporter v7.1.0 999.1K downloads/30d#4,541 on PyPI84
Permissive license MIT Active released

What it is and what it does

draftjs_exporter is a Python library that translates Draft.js ContentState—the internal representation used by the Draft.js React editor—into HTML. Draft.js stores rich text in its own format rather than as HTML, so this exporter bridges that gap for Python backends, particularly in Wagtail/Django environments where you need to render Draft.js content server-side.

The library provides sensible defaults for common HTML elements (paragraphs, lists, emphasis, links) but is designed to be extended: you can define custom block and inline style maps, add decorators to transform line breaks, attach arbitrary attributes to elements, and create React-like custom components. It handles overlapping inline styles and nested lists automatically, converts entity data types (integers, booleans, style objects) to valid HTML attributes, and includes static type annotations throughout.

Use it for:

  • Render Draft.js editor content to HTML on a Wagtail or Django backend without re-implementing the editor in Python.
  • Export rich text from a Draft.js-based frontend editor to a database or file system as semantic HTML.
  • Generate server-side HTML previews of Draft.js content before it is published or stored.
  • Customize HTML output by mapping Draft.js blocks and styles to domain-specific HTML elements or CSS classes.
  • Build a content pipeline where Draft.js ContentState is processed, validated, and converted to HTML in a Python service.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Converts Draft.js ContentState (a rich text editor format) to HTML, with configurable block and inline style mappings and support for nested lists and overlapping styles.

Yes. The package is actively maintained, has no security vulnerabilities, zero runtime dependencies, and a permissive MIT license. Install it if you need to convert Draft.js ContentState to HTML in a Python environment—particularly in Wagtail or Django projects. The low friction and stable API make it a straightforward choice for this specific use case.

Install

draftjs-exporter on PyPI

pip

pip install draftjs-exporter

uv

uv add draftjs-exporter

poetry

poetry add draftjs-exporter

Installing draftjs_exporter

Before you install

Low friction: pure Python wheel with no runtime dependencies. Actively maintained with a release 1 day old; supports Python 3.10 through 3.15 and passes mypy type checking.

License in practice

MIT license permits unrestricted use, modification, and distribution in commercial and private projects with minimal obligations.

Quickstart

pip install draftjs_exporter

from draftjs_exporter.html import HTML

config = {'entity_options': {}, 'composite_decorators': []}
exporter = HTML(config)
html_output = exporter.render(content_state)

Requires Python 3.10 or later; content_state must be a valid Draft.js ContentState object (typically a dict with 'blocks' and 'entityMap' keys).

Verify before relying

  • Whether the package handles all Draft.js entity types and block types out of the box or requires custom configuration for non-standard content.
  • Performance characteristics when processing large or deeply nested Draft.js documents.
  • Whether custom component creation (mentioned in description) requires additional dependencies or setup beyond the base installation.

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance actively maintained — 1 days since the last release
Last repo commit
First released
Downloads 999,142/month — #4,541 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: draftjs_exporter-7.1.0-py3-none-any.whl

Development Status :: 5 - Production/StableEnvironment :: Web EnvironmentIntended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.15Topic :: Internet :: WWW/HTTPTopic :: Internet :: WWW/HTTP :: Dynamic ContentTopic :: Internet :: WWW/HTTP :: Site ManagementTopic :: Software Development :: Libraries :: Application FrameworksTopic :: Software Development :: Libraries :: Python ModulesTopic :: Text Editors :: Word ProcessorsTyping :: Typed

Tags

draft.js to html convertercontentstate html exportrich text editor exportdraft.js python libraryconvert draft.js outputhtml generation from draft.js
draft-jswagtail-integrationhtml-generation

More Python Modules packages