Skip to main content

Contentstack Utility

This guide will help you get started with Contentstack Python Utils SDK to build apps powered by Contentstack.

Prerequisites

The latest version of PyCharm or Visual Studio Code

Python 3

Create virtual environment

Activate virtual environment

SDK Installation and Setup

To set up Python Utils SDK, Go to terminal and locate the virtual environment path and type below.

   pip install contentstack_utils

If you are using Contentstack Python SDK in your project by running the following commands, then “contentstack_utils” is already imported into your project.

For the latest version

   pip install Contentstack

For the specific version

   pip install Contentstack==1.5.1

Usage

Let’s learn how you can use Utils SDK to render embedded items.

Create Render Option

To render embedded items on the front-end, use the renderContents function, and define the UI elements you want to show in the front-end of your website, as shown in the example code below:

    from contentstack_utils.utils import Utils
    from contentstack_utils.render.options import Options
    
    json_array = {} # should be type of dictionary or list
    option = Options()
    response = Utils.render_content('html_string', json_array, option)
    print(response)
    

Basic Queries

Contentstack Utils SDK lets you interact with the Content Delivery APIs and retrieve embedded items from the RTE field of an entry.

Fetch Embedded Item(s) from a Single Entry

To get an embedded item of a single entry, you need to provide the stack API key, environment name, content type’s UID, and entry’s UID. Then, use the entry.fetch function as shown below:

import contentstack
    
stack = contentstack.Stack('api_key','delivery_token','environment')
content_type = stack.content_type("content_type_uid")
entry = content_type.entry("entry_uid")
result = entry.fetch()
if result is not None:
   entry = result['entries']
   Utils.render(entry, ['rich_text_editor', 'some_other_text'], Option())
       

Fetch Embedded Item(s) from Multiple Entries

To get embedded items from multiple entries, you need to provide the stack API key, delivery token, environment name, and content type’s UID.

import contentstack

stack = contentstack.Stack('api_key','delivery_token','environment')
query = stack.content_type("content_type_uid").query()
result = query.find()
if result is not None and 'entries' in result:
   entry = result['entries']
   for item in range:
       option = Option()
       Utils.render(item, ['rich_text_editor', 'some_other_text'], option)

Supercharged

To get supercharged items from multiple entries, you need to provide the stack API key, delivery token, environment name, and content type’s UID.

import contentstack

stack = contentstack.Stack('api_key','delivery_token','environment')
query = stack.content_type("content_type_uid").query()
result = query.find()
if result is not None and 'entries' in result:
   entry = result['entries']
   for item in entry:
       option = Option()
       Utils.json_to_html(item, ['paragraph_text'], option)

GraphQL SRTE

To get supercharged items from multiple entries, you need to provide the stack API key, delivery token, environment name, and content type’s UID.

import contentstack

stack = contentstack.Stack('api_key','delivery_token','environment')
query = stack.content_type("content_type_uid").query()
result = query.find()
if result is not None and 'entries' in result:
   entry = result['entries']
   for item in entry:
       option = Option()
       GQL.json_to_html(item, ['paragraph_text'], option)

Metadata

Release files for contentstack-utils 1.6.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for contentstack-utils 1.6.1
File Size Uploaded
contentstack_utils-1.6.1.tar.gz 26.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for contentstack-utils 1.6.1
File Interpreter ABI Platform
contentstack_utils-1.6.1-py3-none-any.whl Python 3 none any Details

Total release size: 60.1 kB

Release files / contentstack_utils-1.6.1.tar.gz

Download URL contentstack_utils-1.6.1.tar.gz
Size 26.3 kB
Tags Source
SHA-256 checksum
How to use checksums
7560526f85ceee85711480c24aba31a62f6dfa1dc51ea4ddbf48b4576a7bf63a
BLAKE2b-256 checksum
How to use checksums
1a82bbe67ea221bcb28a2fb3d93e1a24da81efcd3b48f5caf1c4d8e1e72836ed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / contentstack_utils-1.6.1-py3-none-any.whl

Download URL contentstack_utils-1.6.1-py3-none-any.whl
Size 33.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
925daf875b95aa0beb26c6013c0db027e4c8a12a450e63409f522d21c01d98c1
BLAKE2b-256 checksum
How to use checksums
5ec1500cf85b6e2a8a182a1474caca654d20008100e82121c5a6c39fc0dbc06f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release history Release notifications | RSS feed

This release

1.6.1 This release

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page