contentstack-utils


Namecontentstack-utils JSON
Version 1.3.1 PyPI version JSON
download
home_pagehttps://github.com/contentstack/contentstack-utils-python
Summarycontentstack_utils is a Utility package for Contentstack headless CMS with an API-first approach.
upload_time2024-09-27 11:49:04
maintainerNone
docs_urlNone
authorcontentstack
requires_python>=3.6
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](https://www.jetbrains.com/pycharm/download/) or [Visual Studio Code](https://code.visualstudio.com/download)

[Python 3](https://docs.python-guide.org/starting/installation/#python-3-installation-guides)

[Create virtual environment](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment)

[Activate virtual environment](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/#activating-a-virtual-environment)

## SDK Installation and Setup

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

```python
   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

```python
   pip install Contentstack
```

## For the specific version

```python
   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:

```python
    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:

```python
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. 

```python
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. 

```python
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. 

```python
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)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/contentstack/contentstack-utils-python",
    "name": "contentstack-utils",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": null,
    "author": "contentstack",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/31/65/8eabdbb706c3264b7d140fd77930a354baf5af3a5da852daaceac1298698/contentstack_utils-1.3.1.tar.gz",
    "platform": null,
    "description": "# Contentstack Utility\n\nThis guide will help you get started with Contentstack Python Utils SDK to build apps powered by Contentstack.\n\n## Prerequisites\n\nThe latest version of [PyCharm](https://www.jetbrains.com/pycharm/download/) or [Visual Studio Code](https://code.visualstudio.com/download)\n\n[Python 3](https://docs.python-guide.org/starting/installation/#python-3-installation-guides)\n\n[Create virtual environment](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/#creating-a-virtual-environment)\n\n[Activate virtual environment](https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/#activating-a-virtual-environment)\n\n## SDK Installation and Setup\n\nTo set up Python Utils SDK, Go to terminal and locate the virtual environment path and type below.\n\n```python\n   pip install contentstack_utils\n```\n\nIf you are using Contentstack Python SDK in your project by running the following commands,  then \u201ccontentstack_utils\u201d  is already imported into your project.\n\n## For the latest version\n\n```python\n   pip install Contentstack\n```\n\n## For the specific version\n\n```python\n   pip install Contentstack==1.5.1\n```\n\n## Usage\n\nLet\u2019s learn how you can use Utils SDK to render embedded items. \n\n### Create Render Option\n\nTo 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:\n\n```python\n    from contentstack_utils.utils import Utils\n    from contentstack_utils.render.options import Options\n    \n    json_array = {} # should be type of dictionary or list\n    option = Options()\n    response = Utils.render_content('html_string', json_array, option)\n    print(response)\n    \n```\n\n## Basic Queries\n\nContentstack Utils SDK lets you interact with the Content Delivery APIs and retrieve embedded items from the RTE field of an entry.\n\n## Fetch Embedded Item(s) from a Single Entry\n\nTo get an embedded item of a single entry, you need to provide the stack API key, environment name, content type\u2019s UID, and entry\u2019s UID. Then, use the `entry.fetch` function as shown below:\n\n```python\nimport contentstack\n    \nstack = contentstack.Stack('api_key','delivery_token','environment')\ncontent_type = stack.content_type(\"content_type_uid\")\nentry = content_type.entry(\"entry_uid\")\nresult = entry.fetch()\nif result is not None:\n   entry = result['entries']\n   Utils.render(entry, ['rich_text_editor', 'some_other_text'], Option())\n       \n```\n\n## Fetch Embedded Item(s) from Multiple Entries\n\nTo get embedded items from multiple entries, you need to provide the stack API key, delivery token, environment name, and content type\u2019s UID. \n\n```python\nimport contentstack\n\nstack = contentstack.Stack('api_key','delivery_token','environment')\nquery = stack.content_type(\"content_type_uid\").query()\nresult = query.find()\nif result is not None and 'entries' in result:\n   entry = result['entries']\n   for item in range:\n       option = Option()\n       Utils.render(item, ['rich_text_editor', 'some_other_text'], option)\n```\n\n\n## Supercharged\n\nTo get supercharged items from multiple entries, you need to provide the stack API key, delivery token, environment name, and content type\u2019s UID. \n\n```python\nimport contentstack\n\nstack = contentstack.Stack('api_key','delivery_token','environment')\nquery = stack.content_type(\"content_type_uid\").query()\nresult = query.find()\nif result is not None and 'entries' in result:\n   entry = result['entries']\n   for item in entry:\n       option = Option()\n       Utils.json_to_html(item, ['paragraph_text'], option)\n```\n\n## GraphQL SRTE\n\nTo get supercharged items from multiple entries, you need to provide the stack API key, delivery token, environment name, and content type\u2019s UID. \n\n```python\nimport contentstack\n\nstack = contentstack.Stack('api_key','delivery_token','environment')\nquery = stack.content_type(\"content_type_uid\").query()\nresult = query.find()\nif result is not None and 'entries' in result:\n   entry = result['entries']\n   for item in entry:\n       option = Option()\n       GQL.json_to_html(item, ['paragraph_text'], option)\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "contentstack_utils is a Utility package for Contentstack headless CMS with an API-first approach.",
    "version": "1.3.1",
    "project_urls": {
        "Homepage": "https://github.com/contentstack/contentstack-utils-python"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "43eaaa9281873f20dc52262a1d05c7a1d4fea249d3e8a617712d004ecfe84c89",
                "md5": "b129f4aca7af65d6092ec7b0fa0618e0",
                "sha256": "b3ed12f3fb071ce3bf540ea6ba911b772ac1e90cdb830821f04ab17d4b5eef25"
            },
            "downloads": -1,
            "filename": "contentstack_utils-1.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b129f4aca7af65d6092ec7b0fa0618e0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 20827,
            "upload_time": "2024-09-27T11:49:03",
            "upload_time_iso_8601": "2024-09-27T11:49:03.337084Z",
            "url": "https://files.pythonhosted.org/packages/43/ea/aa9281873f20dc52262a1d05c7a1d4fea249d3e8a617712d004ecfe84c89/contentstack_utils-1.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "31658eabdbb706c3264b7d140fd77930a354baf5af3a5da852daaceac1298698",
                "md5": "5afa8566c77b18edf99c45df534f4603",
                "sha256": "6e111c54c72cb091d04c8f572866c2540fd61303ae1dfd5b50ce7b483f6dad7b"
            },
            "downloads": -1,
            "filename": "contentstack_utils-1.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "5afa8566c77b18edf99c45df534f4603",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 14619,
            "upload_time": "2024-09-27T11:49:04",
            "upload_time_iso_8601": "2024-09-27T11:49:04.583559Z",
            "url": "https://files.pythonhosted.org/packages/31/65/8eabdbb706c3264b7d140fd77930a354baf5af3a5da852daaceac1298698/contentstack_utils-1.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-27 11:49:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "contentstack",
    "github_project": "contentstack-utils-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "contentstack-utils"
}
        
Elapsed time: 0.28187s