Contentstack offers five regions North America (NA), Europe (EU), Azure North America (AZURE_NA), Azure Europe (AZURE_EU), and GCP North America (GCP_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, Azure NA, or Azure EU 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 the 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.
By default, the SDK uses the North American region. Configuration changes are not required for North American region users.
Refer the below code if you want to use the Europe, Azure North America, Azure Europe, or GCP North America region.
import contentstack
stack = contentstack.Stack("api_key", "delivery_token", "environment", region = "ContentstackRegion.AZURE_EU")
Once you have initialized the SDK, you can query entries to fetch the required content.
For Setting the branch for Europe, Azure North America, Azure Europe, or GCP North America, refer the code below
For Setting Branch:
If you want to initialize SDK in a particular branch use the code given below:
import contentstack
stack = contentstack.Stack(api_key='api_key', delivery_token='delivery_token',environment= 'environment', branch='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.
Get a Single Entry
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")
entry = content_type.entry("entry_uid")
response = 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')
query = stack.content_type("content_type_uid").query()
response = query.find()
Note: By default, the limit for response details per request is 100, with the maximum limit set at 250.