Contentstack Utils

1.5.0 · active · verified Thu Apr 16

contentstack_utils is a Python utility package designed to assist with processing data from the Contentstack headless CMS. Its primary function is to convert Rich Text Editor (RTE) content, including Supercharged RTE (SRTE) with embedded items, from Contentstack's JSON format into HTML. The current version is 1.5.0, with minor releases happening every few months.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to convert a Contentstack Rich Text Editor (RTE) JSON structure into renderable HTML using the `ContentstackUtils.json_to_html` method. This is the most common use case for the library.

import json
from contentstack_utils import ContentstackUtils

# Sample Rich Text Editor JSON from Contentstack
# This structure is typically found under the 'json' key of an RTE field.
rte_content_json = [
    {
        "type": "doc",
        "children": [
            {
                "type": "p",
                "children": [
                    {
                        "text": "Hello from Contentstack Rich Text Editor!"
                    }
                ]
            },
            {
                "type": "p",
                "children": [
                    {
                        "type": "a",
                        "attrs": {
                            "href": "https://www.contentstack.com",
                            "target": "_blank",
                            "rel": ["noopener", "noreferrer"]
                        },
                        "children": [
                            {
                                "text": "Visit Contentstack"
                            }
                        ]
                    }
                ]
            }
        ]
    }
]

# Convert the RTE JSON to HTML
html_output = ContentstackUtils.json_to_html(rte_content_json)

print("Converted HTML output:")
print(html_output)

view raw JSON →