contentstack package

Submodules

contentstack.asset module

Assets refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded in your Contentstack repository for future use.

These files can be attached and used in multiple entries.

class contentstack.asset.Asset(http_instance, uid=None)[source]

Bases: object

Asset refer to all the media files (images, videos, PDFs, audio files, and so on).

environment(environment)[source]

Provide the name of the environment if you wish to retrieve the assets published in a particular environment.

:param environment {str} - name of the environment

Returns

Asset, so we can chain the call

[Example]:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> asset = stack.asset(uid='asset_uid')
>>> asset = asset.environment('production')
fetch()[source]

This call fetches the latest version of a specific asset of a particular stack.

Returns

json response of asset

[Example]:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> asset = stack.asset(uid='asset_uid')
>>> result = asset.fetch()
include_dimension()[source]

Include the dimensions (height and width) of the image in the response. Supported image types: JPG, GIF, PNG, WebP, BMP, TIFF, SVG, and PSD.

Returns

Asset, so we can chain the call

Example:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> asset = stack.asset(uid='asset_uid')
>>> asset = asset.include_dimension()
include_fallback()[source]

Retrieve the published content of the fallback locale if an entry is not localized in specified locale

Returns

Asset, so we can chain the call

Example:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> asset = stack.asset(uid='asset_uid')
>>> result = asset.include_fallback().fetch()
params(key, value)[source]

params is used to pass additional parameters to the asset query

Parameters
  • key – key of the query parameter

  • value – value of the query parameter

Returns

Asset, so we can chain the call

Example:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> asset = stack.asset(uid='asset_uid')
>>> asset = asset.params('key', 'value')
relative_urls()[source]

Include the relative URLs of the assets in the response.

Returns

Asset, so we can chain the call

Example:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> asset = stack.asset(uid='asset_uid')
>>> asset = asset.relative_urls()
remove_environment()[source]

Removes environment from the request params

Returns

Asset, so we can chain the call

[Example]:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> asset = stack.asset(uid='asset_uid')
>>> asset = asset.remove_header()
>>> asset.fetch()

contentstack.assetquery module

This call fetches the list of all the assets of a particular stack. It also returns the content of each asset in JSON format. You can also specify the environment of which you wish to get the assets.

class contentstack.assetquery.AssetQuery(http_instance)[source]

Bases: contentstack.basequery.BaseQuery

This call fetches the list of all the assets of a particular stack.

environment(environment)[source]

Provide the name of the environment if you wish to retrieve the assets published in a particular environment.

Parameters

environment – environment of the stack

Returns

AssetQuery - so we can chain the call

[Example]:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> result = stack.asset_query().environment('production').find()
find()[source]

This call fetches the list of all the assets of a particular stack. It also returns the content of each asset in JSON format. Learn more about Assets [https://www.contentstack.com/docs/content-managers/work-with-assets].

Returns

json result, List of asset object

[Example]:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> result = stack.asset_query().find()
include_dimension()[source]

Include the dimensions (height and width) of the image in the response. Supported image types: JPG, GIF, PNG, WebP, BMP, TIFF, SVG, and PSD

Returns

AssetQuery: so we can chain the call

[Example]:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> result = stack.asset_query().include_dimension().find()
include_fallback()[source]

Retrieve the published content of the fallback locale if an entry is not localized in specified locale.

Returns

AssetQuery, so we can chain the call

Example:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> result = stack.asset_query().include_fallback().find()
locale(locale: str)[source]

Enter locale code. e.g., en-us This retrieves published entries of specific locale..

Returns

AssetQuery, so we can chain the call

Example:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> result = stack.asset_query().locale('en-us').find()
relative_url()[source]

include the relative URLs of the assets in the response.

Returns

AssetQuery: so we can chain the call

[Example]:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> result = stack.asset_query().relative_url().find()
version(version)[source]

Specify the version number of the asset that you wish to retrieve. If the version is not specified, the details of the latest version will be retrieved. To retrieve a specific version, keep the environment parameter blank.

Parameters

version – version number of the asset that you wish to retrieve

Returns

AssetQuery: so we can chain the call

[Example]:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> result = stack.asset_query().version(3).find()

contentstack.basequery module

Missing docstring Common Query for Entry and Assets

class contentstack.basequery.BaseQuery[source]

Bases: object

Common Query class works for Query As well as Asset

add_params(param: dict)[source]

Adds Parameters to the to the request Arguments:

param {dict} – parameters

Returns:

[self] – Class instance, So that method chaining can be performed

include_count()[source]

Retrieve count and data of objects in result Returns:

[Query] – Query object, so you can chain this call.

[Example:]
>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'access_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> query = content_type.query()
>>> query = query.include_count()
>>> result = query.find()
limit(limit_count: int)[source]

A limit on the number of objects to return. :param limit_count: :return: self

order_by_ascending(key: str)[source]

you can sort them in the ascending order with respect to the value of a specific field in the response body.

Parameters

key – key on which ascending order to be implemented

Returns

self

order_by_descending(key: str)[source]

you can sort them in the descending order with respect to the value of a specific field in the response body. :param key: key on which descending order to be implemented :return: self - Class instance, So that method chaining can be performed

param(key: str, value)[source]

Adds Parameters to the to the request

Arguments:

key {str} – Key of the parameter value {[any]} – Value of the parameter

Raises:

KeyError: When None found in key or value

Returns:

[self] – instance of the class

[Example]
>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'access_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> query = content_type.query()
>>> query = query.param("key", "value")
>>> result = query.find()
query(key: str, value)[source]

Adds key value pairs to the to the query parameters Arguments:

key {str} – key of the query param value {any} – value of query param

Raises:

KeyError: when key or value found None

Returns:

self– Class instance, So that method chaining can be performed

remove_param(key: str)[source]

Remove provided query key from custom query if exist. :param key {str} – The key to be constrained :return: self – So that method chaining can be performed

[Example]:
>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> query = content_type.query()
>>> query = query.remove_query("query_key")
>>> result = query.find()
skip(skip_count: int)[source]

The number of objects to skip before returning any. skip_count No of objects to skip from returned objects :param skip_count: :return: self

where(field_uid: str, query_operation: contentstack.basequery.QueryOperation, fields=None)[source]

Get entries containing the field values matching the condition in the query. Arguments:

field_uid {str} – [accept field uid for the operation] query_operation {QueryOperation} – Type of operation to perform fields {list} - list of string

class contentstack.basequery.QueryOperation(value)[source]

Bases: enum.Enum

QueryOperation is enum that Provides Options to perform operation to query the result.

Available Options for QueryOperation are below. EQUALS, NOT_EQUALS, INCLUDES, EXCLUDES, IS_LESS_THAN, IS_LESS_THAN_OR_EQUAL IS_GREATER_THAN, IS_GREATER_THAN_OR_EQUAL, EXISTS, MATCHES

Arguments:

enum {QueryOperation} – Type of operation to perform

EQUALS = ''
EXCLUDES = '$nin'
EXISTS = '$exists'
INCLUDES = '$in'
IS_GREATER_THAN = '$gt'
IS_GREATER_THAN_OR_EQUAL = '$gte'
IS_LESS_THAN = '$lt'
IS_LESS_THAN_OR_EQUAL = '$lte'
MATCHES = '$regex'
NOT_EQUALS = '$ne'

contentstack.contenttype module

Content type defines the structure or schema of a page or a section of your web or mobile property. To create content for your application, you are required to first create a content type, and then create entries using the content type.

class contentstack.contenttype.ContentType(http_instance, content_type_uid)[source]

Bases: object

Content type defines the structure or schema of a page or a section of your web or mobile property. To create content for your application, you are required to first create a content type, and then create entries using the content type.

entry(entry_uid: str)[source]

An entry is the actual piece of content created using one of the defined content types. :param entry_uid: {str} – unique ID of the entry that you wish to fetch :return: Entry – Returns the Entry class object so we can chain the entry functions

[Example:]
>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> entry = content_type.entry(uid='entry_uid')
fetch()[source]

This method is useful to fetch ContentType of the of the stack. :return:dict – contentType response —————————— Example:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> some_dict = {'abc':'something'}
>>> response = content_type.fetch(some_dict)
find(params=None)[source]

This method is useful to fetch ContentType of the of the stack. :param params: dictionary of params :return:dict – contenttype response —————————— Example:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> content_type = stack.content_type()
>>> some_dict = {'abc':'something'}
>>> response = content_type.find(param=some_dict)
query()[source]

It returns query class object so we can query on entry of specified ContentType :return: Query – query object instance, so we can chain the query functions to it. —————————— [Example:]

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> query = content_type.query()

contentstack.entry module

The Get a single entry request fetches a particular entry of a content type. API Reference: https://www.contentstack.com/docs/developers/apis/content-delivery-api/#single-entry

class contentstack.entry.Entry(http_instance, content_type_uid, entry_uid)[source]

Bases: contentstack.entryqueryable.EntryQueryable

An entry is the actual piece of content that you want to publish. Entries can be created for one of the available content types.

Entry works with version={version_number} environment={environment_name} locale={locale_code}

environment(environment)[source]

Enter the name of the environment of which the entries needs to be included Example: production :param environment: {str} name of the environment of which the entries needs to be included. :return: Entry, so you can chain this call. —————————— Example:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> entry = content_type.entry(uid='entry_uid')
>>> entry.environment('production')
>>> result = entry.fetch()
fetch()[source]

Fetches the latest version of the entries from stack :return: Entry, so you can chain this call. ——————————- [Example:]

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> entry = content_type.entry('uid')
>>> result = entry.fetch()
include_fallback()[source]

Retrieve the published content of the fallback locale if an entry is not localized in specified locale. :return: Entry, so we can chain the call —————————- Example:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> entry = content_type.entry(uid='entry_uid')
>>> entry = entry.include_fallback()
>>> result = entry.fetch()
param(key: str, value: any)[source]

This method is useful to add additional Query parameters to the entry :param key: {str} – key The key as string which needs to be added to an Entry :param value: {object} – value The value as string which needs to be added to an Entry :return: Entry, so you can chain this call. —————————– Example:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> entry = content_type.entry(uid='entry_uid')
>>> entry = entry.param('key', 'value')
>>> result = entry.fetch()
version(version)[source]

When no version is specified, it returns the latest version To retrieve a specific version, specify the version number under this parameter. In such a case, DO NOT specify any environment. Example: 4

Parameters

version – {int} – version

Returns

Entry, so you can chain this call.

Example:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> entry = content_type.entry(uid='entry_uid')
>>> entry.version(4)
>>> result = entry.fetch()

contentstack.entryqueryable module

EntryQueryable class contains common functions that is used as parents class for the query and entry classes

class contentstack.entryqueryable.EntryQueryable[source]

Bases: object

This class is base class for the Entry and Query class that shares common functions

add_param(key: str, value: str)[source]

This method adds key and value to an Entry. :param key: The key as string which needs to be added to an Entry :param value: The value as string which needs to be added to an Entry :return: self: object, so you can chain this call.

Example: Call from Query =>
>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> query = stack.content_type('content_type_uid').query()
>>> query = query.include_reference_content_type_uid()
>>> result = query.find()
Example: Call from Entry =>
>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> entry = stack.content_type('content_type_uid').entry('entry_uid')
>>> entry = entry.include_reference_content_type_uid()
>>> result = entry.fetch()
excepts(field_uid: str)[source]

Specifies list of field_uid that would be excluded from the response. It refers to the top-level fields of the schema :param field_uid: to be excluded from the response. :return: self – so you can chain this call.

include_content_type()[source]

This method also includes the ContentType in the entry :return: self: so you can chain this call. ——————————- [Example: for Entry]

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> entry = content_type.entry('uid')
>>> entry.include_content_type()
>>> result = entry.fetch()

[Example: for Query:]

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> query = content_type.query()
>>> query.include_content_type()
>>> result = query.find()
include_reference(field_uid)[source]

When you fetch an entry of a content type that has a reference field, by default, the content of the referred entry is not fetched. It only fetches the UID of the referred entry, along with the content of the specified entry.

Note: The maximum reference depth limit to which a multiple content type referencing Reference field works is three levels deep

Arguments: Array of the only reference keys to be included in response field_uid {str or list of str} – [str/list of str] of field_uid on which include operation to perform

Returns:

self – So you can chain this call.

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> entry = stack.content_type('content_type')
>>> entry("entry_uid").include_reference(["categories", "brand"])
>>> result = entry.fetch()
include_reference_content_type_uid()[source]

This method also includes the content type UIDs of the referenced entries returned in the response Returns:

return

self: so you can chain this call.

[Example for Query]
>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> query = content_type.query()
>>> query = query.include_reference_content_type_uid()
>>> result = query.find()
[Example for Entry]
>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> entry = stack.content_type('content_type_uid').entry('entry_uid')
>>> entry = entry.include_reference_content_type_uid()
>>> result = entry.fetch()
locale(locale: str)[source]

Language code of which the entries needs to be included. Only the entries published in this locale will be displayed

Arguments:

locale {str} – locale_code of the language of which the entries needs to be included. Only the entries published in this locale will be displayed

Returns

self: so you can chain this call.

Example (locale for Entry):
>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> entry = content_type.entry(uid='entry_uid')
>>> entry.locale('en-us')
>>> result = entry.fetch()
Example (locale for Query):
>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> query = content_type.query()
>>> query.locale('en-us')
>>> result = query.find()
only(field_uid: str)[source]

Specifies an array of only keys in BASE object that would be included in the response. It refers to the top-level fields of the schema :param field_uid: Array of the only reference keys to be included in response Returns:

self – so you can chain this call.

contentstack.image_transform module

The Image Delivery API is used to retrieve, manipulate and/or convert image files of your Contentstack account and deliver it to your web or mobile properties. It is an second parameter in which we want to place different manipulation key and value in array form ImageTransform method is define for image manipulation with different transform_params in second parameter in array form

class contentstack.image_transform.ImageTransform(http_instance, image_url, **kwargs)[source]

Bases: object

The Image Delivery API is used to retrieve, manipulate and/or convert image files

get_url()[source]

Returns a complete url after concatenate with parameters :return: updated asset url —————————— Example:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> image_url = stack.image_transform('image_url', width=100, height=100)
>>> result = image_url.fetch()

contentstack.query module

Contentstack provides certain queries that you can use to fetch filtered results

class contentstack.query.Query(http_instance, content_type_uid)[source]

Bases: contentstack.basequery.BaseQuery, contentstack.entryqueryable.EntryQueryable

Contentstack provides certain queries that you can use to fetch filtered results. You can use queries for Entries API requests. [API Reference]:https://www.contentstack.com/docs/developers/apis/content-delivery-api/#queries]

Example:
>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> query = stack.content_type('content_type_uid').query()
>>> result = query.locale('locale-code').excepts('field_uid').limit(4).skip(5).find()
find()[source]

It fetches the query result. List of Entry objects. Raises:

ValueError: If content_type_id is None ValueError: If content_type_id is empty or not str type

Returns:

list[Entry] – List of <contentstack.entry.Entry>

[Example]:
>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> query = content_type.query()
>>> result = query.find()
find_one()[source]

It returns only one result. Returns:

list[Entry] – List of <contentstack.entry.Entry>

[Example]:
>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> query = content_type.query()
>>> result = query.find_one()
include_fallback()[source]

Retrieve the published content of the fallback locale if an entry is not localized in specified locale.

Returns

Query, so we can chain the call

Example:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> query = content_type.query()
>>> query = query.include_fallback()
>>> result = query.find()
query_operator(query_type: contentstack.query.QueryType, *query_objects)[source]

Get entries that satisfy all the conditions provided in the ‘$and’ query. Arguments:

query_objects {Query} – query_objects for variable number of arguments of type Query Object.

Raises:

ValueError: If query_objects is None

Returns:

Query – Query object, so you can chain this call.

[Example]:
>>> import contentstack
>>> from contentstack.basequery import QueryOperation
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> query = stack.content_type('content_type1').query()
>>> self.query1 = stack.content_type('content_type2').query()
>>> self.query2 = stack.content_type('content_type3').query()
>>> query1 = self.query1.where("price", QueryOperation.IS_LESS_THAN, fields=90)
>>> query2 = self.query2.where("discount", QueryOperation.INCLUDES, fields=[20, 45])
>>> query = query.query_operator(query1, query2)
>>> result = query.find()
search(value: str)[source]

This method provides only the entries matching the specified value. Arguments:

value {str} – value used to match or compare

Raises:

ValueError: If value is None ValueError: If type od value is not str

Returns:

[Query] – Query object, so you can chain this call.

[Example]
>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> query = content_type.query()
>>> query = query.search("search_keyword")
>>> result = query.find()
tags(*tags)[source]

Include tags with which to search entries accepts variable-length argument lists Arguments:

tags {list of str} – tags accepts variable-length argument lists to search entries.

Returns:

[Query] – Query object, so you can chain this call.

Example:
>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> query = content_type.query()
>>> query = query.tags('black', 'gold', 'silver')
>>> result = query.find()
where_in(key: str, query_object)[source]

Get entries having values based on referenced fields. This query retrieves all entries that satisfy the query conditions made on referenced fields. Arguments:

key {str} – The key to be constrained

Raises:

ValueError: If key is None ValueError: If key is not str type

Returns:

[Query] – Query object, so you can chain this call.

[Example]
>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> query = content_type.query()
>>> query = query.where_in("brand")
>>> result = query.find()
Parameters

key

where_not_in(key, query_object)[source]

Get entries having values based on referenced fields. This query works the opposite of $in_query and retrieves all entries that does not satisfy query conditions made on referenced fields. Arguments:

key {str} – The key to be constrained

Raises:

ValueError: If key is None ValueError: If key is not str type

Returns:

[Query] – Query object, so you can chain this call.

[Example]
>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> content_type = stack.content_type('content_type_uid')
>>> query = content_type.query()
>>> query = query.where_not_in("brand")
>>> result = query.find()
class contentstack.query.QueryType(value)[source]

Bases: enum.Enum

Get entries that satisfy all the conditions provided by enum(AND, OR) enum ([AND, OR]): Get entries that satisfy all the conditions provided by enum AND: Get entries that satisfy all the conditions provided in the ‘$and’ query OR: Get entries that satisfy all the conditions provided in the ‘$or’ query

AND = '$and'
OR = '$or'

contentstack.stack module

Class that wraps the credentials of the authenticated user. Think of this as a container that holds authentication related data.

class contentstack.stack.ContentstackRegion(value)[source]

Bases: enum.Enum

Sets region for the contentstack

EU = 'eu'
US = 'us'
class contentstack.stack.Stack(api_key, delivery_token, environment, host='cdn.contentstack.io', version='v3', region=<ContentstackRegion.US: 'us'>)[source]

Bases: object

A stack can be defined as a pool of data or a container that holds all the content/assets related to a site. It is a collaboration space where multiple users can work together to create, edit, approve, and publish content. (API Reference)[https://www.contentstack.com/docs/developers/apis/content-delivery-api/#stack]:

asset(uid)[source]

Assets refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded in your Contentstack repository for future use. :param uid: asset_uid of the Asset :return: Asset

Example: provide asset_uid to fetch single asset:
>>> import contentstack
>>> stack = Stack('api_key', 'delivery_token', 'environment')
>>> asset_instance = stack.asset(uid='asset_uid')
>>> result = asset_instance.fetch()
asset_query()[source]

Assets refer to all the media files (images, videos, PDFs, audio files, and so on) uploaded in your Contentstack repository for future use. :return: Asset Instance —————————– Example: [All Assets]:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> asset_query = stack.asset_query()
>>> assets = asset_query.find()
content_type(content_type_uid=None)[source]

Content type defines the structure or schema of a page or a section of your web or mobile property. :param content_type_uid: :return: ContentType

property get_api_key

return: api_key of the stack

property get_delivery_token

return: delivery_token of the stack

property get_environment

return: environment of the stack

property get_headers

return: validating credentials http header of the stack

image_transform(image_url, **kwargs)[source]

This document is a detailed reference to Contentstack’s Image Delivery API and covers the parameters that you can add to the URL to retrieve, manipulate (or convert) image files and display it to your web or mobile properties. :param image_url: base url on which queries to apply :param kwargs: append queries to the asset URL. :return: instance of ImageTransform

pagination(pagination_token: str)[source]

If the result of the initial sync (or subsequent sync) contains more than 100 records, the response would be paginated. It provides pagination token in the response. However, you do not have to use the pagination token manually to get the next batch. :param pagination_token: :return: list of sync items —————————— Example:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> result = stack.pagination('pagination_token')
sync_init(content_type_uid=None, from_date=None, locale=None, publish_type=None)[source]

Constructs and initialises sync if no params provided else below mentioned params can be provided to get the response accordingly :param content_type_uid: subsequent syncs will only include the entries

of the specified content_type.

Parameters
  • from_date – use from_date and specify the start date as its value.

  • locale – specify the locale code as its value. However, if you do this, the subsequent syncs will only include the entries of the specified locales.

  • publish_type – Use the type parameter to get a specific type of content. pass as follows:

asset_published, entry_published, asset_unpublished, asset_deleted, entry_unpublished, entry_deleted, or content_type_deleted. :return: list of sync items ——————————- Example:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> result = stack.sync_init(content_type_uid='content_type_uid',
             from_date='date', locale='en-us', publish_type='asset_published')
sync_token(sync_token)[source]

You can use the sync token (that you receive after initial sync) to get the updated content next time. The sync token fetches only the content that was added after your last sync, and the details of the content that was deleted or updated. :param sync_token: sync_token :return: list of Sync Result —————————— [Example]:

>>> import contentstack
>>> stack = contentstack.Stack('api_key', 'delivery_token', 'environment')
>>> result = stack.sync_token('sync_token')

contentstack.utility module

Utils contentstack Last modified by Shailesh Mishra on 06/08/20. Copyright 2019 Contentstack. All rights reserved.

class contentstack.utility.Utils[source]

Bases: object

Utility for the contentstack

static config_logging()[source]

Setting up logging

static do_url_encode(params)[source]

To encode url with query parameters :param params: :return: encoded url

static get_complete_url(base_url: str, params: dict)[source]

creates complete url using base_url and their respective parameters :param base_url: :param params: :return:

static log(message)[source]

this generates log message

static setup_logger()[source]

setup logger for the application

contentstack.utility.config_logging(logging_type: 30)[source]

This is to create logging config :param logging_type: Level of the logging :return: basicConfig instance

Module contents

The __init__.py files are required to make Python treat the directories as containing packages; this is done to prevent directories with a common name, such as string, from unintentionally hiding valid modules that occur later on the module search path

Used: Safety checks your installed dependencies for known security vulnerabilities file __init__.py contains package information like __author__, __status__, __version__, __endpoint__ and __email__