# Search for installation instructions

capturedAt: 2026-11-05T07:40:05.018602+00:00
startUrl: https://wagtail.github.io/draftjs_exporter/
query: getting started
inputSelector: input[data-md-component="search-query"]
resultSelector: .md-search-result__link[href="https://wagtail.github.io/draftjs_exporter/getting-started/"]
actualUrl: https://wagtail.github.io/draftjs_exporter/getting-started/
completionSelector: article
expectedText: pip install draftjs_exporter
cookies: []
observedResult: Found installation command and complete first-render example without an account, payment, personal-data fields or external navigation.
limitations: Anonymous desktop Chromium with keyboard text entry and pointer result selection; no representative-user testing, assistive-technology test, geographic comparison, retention verification or performance measurement.

Actual article excerpt:

Getting started¶

Draft.js stores data in a JSON representation based on blocks, representing lines of content in the editor, annotated with entities and styles to represent rich text. To understand the data model in depth, read Content state first.

This exporter takes the Draft.js ContentState data as input, and outputs HTML based on its configuration. To get started, install the package:

pip install draftjs_exporter


We support all supported Python versions. For legacy Python versions, find compatible releases in the CHANGELOG.

In your code, create an exporter and use the render method to produce HTML. Pass an empty config dict to use the default block and style maps — see Configuration to customize them, and to register the entity decorators (links, images, embeds) that have no defaults.

from draftjs_exporter import HTML



exporter = HTML({})



html = exporter.render(

    {

        "entityMap": {},

        "blocks": [

            {

                "key": "6m5fh",

                "text": "Hello, world!",

                "type": "unstyled",

                "depth": 0,

                "inlineStyleRanges": [],

                "entityRanges": [],

            }

        ],

    }

)



print(html)


For details on the ContentState structure of blocks / inline styles / entities, read our content state overview.

You can also run an example by downloading this repository and then using python example.py, or by using our online Draft.js demo.

By default, the exporter uses a dependency-free string engine to build the DOM tree. If you need HTML escaping and sanitization, or have an existing lxml/html5lib setup, see Alternative engines to pick the right one.

Type annotations¶

The exporter's codebase uses static type annotations throughout, and is type-checked in CI. Reusable types are made available so you can annotate your own components:

from draftjs_exporter import DOM, Element, Props





def image(props: Props) -> Element:

    return DOM.create_element(

        "img",

        {

            "src": props.get("src"),

            "width": props.get("width"),

            "height": props.get("height"),

            "alt": props.get("alt"),

        },

    )


See Custom components for the full component API.

Next steps¶
Configuration – map Draft.js block types, styles, and entities to HTML.
Custom components – render arbitrary markup from entity and block data.
API reference – the full public API.
Troubleshooting – known issues and implementation details.
October 15, 2026
 
July 8, 2026