Skip to main content

Contentstack is a headless CMS with an API-first approach.

Project description

#Contentstack

build Coverage pip python GitHub license GitHub stars

Python SDK for Contentstack

Contentstack is a headless CMS with an API-first approach. It is a CMS that developers can use to build powerful cross-platform applications in their favorite languages. Build your application frontend, and Contentstack will take care of the rest. Read More.

Contentstack provides Python SDK to build application on top of Python. Given below is the detailed guide and helpful resources to get started with our Python SDK.

Prerequisite

You will need python 3 installed on your machine. You can install it from here.

Setup and Installation

To use the Contentstack Python SDK to your existing project, perform the steps given below:

Install contentstack pip

pip install contentstack

Install latest contentstack package from the PyPI

This is the preferred method to install contentstack, as it will always install the most recent stable release. If you don't have pip installed, this Python installation guide can guide you through the process

Key Concepts for using Contentstack

Stack

A stack is like a container that holds the content of your app. Learn more about Stacks.

Content Type

Content type lets you define the structure or blueprint of a page or a section of your digital property. It is a form-like page that gives Content Managers an interface to input and upload content. Read more.

Entry

An entry is the actual piece of content created using one of the defined content types. Learn more about Entries.

Asset

Assets refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded to Contentstack. These files can be used in multiple entries. Read more about Assets.

Environment

A publishing environment corresponds to one or more deployment servers or a content delivery destination where the entries need to be published. Learn how to work with Environments.

Contentstack Python SDK: 5-minute Quickstart

Initializing your SDK

To initialize the SDK, specify application API key, access token, and environment name of the stack as shown in the snippet given below, You can provide optional parameters for config:

stack = contentstack.Stack('api_key', 'delivery_token', 'environment')

To get the API credentials mentioned above, log in to your Contentstack account and then in your top panel navigation, go to Settings > Stack to view the API Key and Access Token.

Querying content from your stack

To retrieve a single entry from a content type use the code snippet given below:

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()
Get Multiple Entries

To retrieve multiple entries of a particular content type, use the code snippet given below:

stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
query = stack.content_type("content_type_uid").query()
result = query.find()

Advanced Queries

You can query for content types, entries, assets and more using our Python API Reference.

Python API Reference Doc

Working with Images

We have introduced Image Delivery APIs that let you retrieve images and then manipulate and optimize them for your digital properties. It lets you perform a host of other actions such as crop, trim, resize, rotate, overlay, and so on.

For example, if you want to crop an image (with width as 300 and height as 400), you simply need to append query parameters at the end of the image URL, such as, https://images.contentstack.io/v3/assets/download?crop=300,400. There are several more parameters that you can use for your images.

Read Image Delivery API documentation.

You can use the Image Delivery API functions in this SDK as well. Here are a few examples of its usage in the SDK.

image = stack.image_transform(url, {'quality': 100}).get_url()
image = stack.image_transform(url, {'width': 100, 'height': 100}).get_url()
image = stack.image_transform(url, {'auto': 'webp'}).get_url()

Using the Sync API with Python SDK

The Sync API takes care of syncing your Contentstack data with your application and ensures that the data is always up-to-date by providing delta updates. Contentstack’s Python SDK supports Sync API, which you can use to build powerful applications.

stack = contentstack.Stack('api_key', 'delivery_token', 'environment')  # initialize sync
response = stack.sync_init()  # sycn using sync token
response = stack.sync_token('sync_token')  # sycn using pagination token
response = stack.pagination('pagination_token')  # sync using multiple parameters
response = stack.sync_init(publish_type='entry_published', content_type_uid='content_type_uid')

Read through to understand how to use the Sync API with Contentstack Python SDK.

Using the Sync API with Python SDK

Helpful Links

The MIT License (MIT)

Copyright © 2012-2025 Contentstack. All Rights Reserved

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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-2.4.1.tar.gz (34.0 kB view details)

Uploaded Source

Built Distribution

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

contentstack-2.4.1-py3-none-any.whl (32.7 kB view details)

Uploaded Python 3

File details

Details for the file contentstack-2.4.1.tar.gz.

File metadata

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

File hashes

Hashes for contentstack-2.4.1.tar.gz
Algorithm Hash digest
SHA256 6cd90dfb14acf30a902bb1533b6995895afdf29cca013eecc0bc70660e144b1b
MD5 f73f314d256cd3f5c74e8deb1461457c
BLAKE2b-256 20d84a1c33c7115725173f96eb93eacefd17cd4e99afb6e95be98791df191d6e

See more details on using hashes here.

File details

Details for the file contentstack-2.4.1-py3-none-any.whl.

File metadata

  • Download URL: contentstack-2.4.1-py3-none-any.whl
  • Upload date:
  • Size: 32.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for contentstack-2.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7cdf35da7cd6ec0283b1353a9c538ad9286babaa69c3f3b75f5f2741db8c5a47
MD5 bcce2d4fa0816c7d94d06921a5af6d55
BLAKE2b-256 5c3c8622b4cbfc468a27ca744729558d00301cc329e38b54b4473cbf23a0885b

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