Skip to main content

contentstack_utils is a Utility package for Contentstack headless CMS with an API-first approach.

Project description

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)

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

contentstack_utils-1.5.0.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

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

contentstack_utils-1.5.0-py3-none-any.whl (26.7 kB view details)

Uploaded Python 3

File details

Details for the file contentstack_utils-1.5.0.tar.gz.

File metadata

  • Download URL: contentstack_utils-1.5.0.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for contentstack_utils-1.5.0.tar.gz
Algorithm Hash digest
SHA256 9641cd67bc230f0d05827d0c33b0df7af48e2ddb30c795428c759225975564d2
MD5 5ae8f16f9a8040ba5fd783cf762b2aa7
BLAKE2b-256 2f1567272c9aa30d038fc6c0d1e0cce60c868a9bf4e7340671dc3e7317a78811

See more details on using hashes here.

File details

Details for the file contentstack_utils-1.5.0-py3-none-any.whl.

File metadata

File hashes

Hashes for contentstack_utils-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0f2d02e261c2268bff3250bedb4e8a8e1d2728a8c201a2b37efff28bfa3d9581
MD5 54891182e160f18c136444f3bbaba1bf
BLAKE2b-256 ddc2dc1ec3a5c70462a8af07ad14c07ef4b1298d73b82783a03c2164bb88651c

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