Was this article helpful?
Thanks for your feedback
This guide will help you get started with Contentstack Python SDK to build apps powered by Contentstack.
To use the Contentstack Python SDK with your existing project, perform the following steps:
mkdir project_name cd project_name
python3 -m venv venv
source venv/bin/activate
pip install contentstack
You can download the latest dependency version here.
Contentstack offers three regions (North America (NA), Europe (EU) and Azure North America (NA) as data centers to store customers' account details and data. These regions are independent of each other and therefore have a dedicated set of instructions to use SDKs offered by Contentstack.
To use SDKs for the Europe and Azure NA region, you will have to make certain changes in the configuration of the SDK, as detailed below, and the rest of the instructions remain the same.
To initialize the SDK, the stack’s API key, delivery token, and name of the environment where you will publish the content, as shown in the snippet below:
import contentstack stack = contentstack.Stack(api_key='api_key', delivery_token='delivery_token', environment='environment')
Note: By default, the SDK uses the North American region. Configuration changes are not required for North American region users.
For Europe or Azure North America, check the code of your region and configure your SDK.
Once you have initialized the SDK, you can query entries to fetch the required content.
For Setting the branch for Europe or Azure North America, check the code of your region and initialize SDK in a particular branch.
Contentstack SDKs let you interact with the Content Delivery APIs and retrieve content from Contentstack. They are read-only in nature. The SDKs fetch and deliver content from the nearest server via Fastly, our powerful and robust CDN.
To retrieve a single entry from a content type, use the code snippet given below:
import contentstack stack = contentstack.Stack(api_key='api_key', delivery_token='delivery_token', environment='environment') contentType = stack.content_type("content_type_uid") blog_entry = content_type.entry("entry_uid") blog_entry.fetch()
Get Multiple Entries
To retrieve multiple entries of a particular content type, use the code snippet given below:
import contentstack stack = contentstack.Stack(api_key='api_key', delivery_token='delivery_token', environment='environment') blog_query = stack.content_type("content_type_uid").query() Response = blog_query.find()
These were examples of some of the basic queries of the SDK. For advanced queries, refer to Contentstack Python SDK API reference documentation.
Note: Currently, the Python SDK does not support multiple content types referencing in a single query. For more information on how to query entries and assets, refer the Queries section of our Content Delivery API documentation.
In a single instance, the Get Multiple Entries query will retrieve only the first 100 items of the specified content type. You can paginate and retrieve the rest of the items in batches using the skip and limit parameters in subsequent requests.
stack = contentstack.Stack(api_key='api_key', delivery_token='delivery_token', environment='environment') query = stack.content_type('content_type_uid').query() result = query.locale('locale-code').limit(20).skip(20).find()
Was this article helpful?
Thanks for your feedback