Entry
Entry
An entry is one piece of content created from a content type. Use this class to
- read one published entry by its UID
- choose the locale and environment the request reads
- control which fields, references, and embedded items the response carries
- move to the variants of that entry
content_type.entry() is the only way to get an instance, and it takes one argument:
| Name | Type | Description |
|---|---|---|
| entry_uid | str | UID of the entry to read. |
The content type UID comes from the stack.content_type('<CONTENT_TYPE_UID>') call in front of it, so both UIDs reach the request through the chain.
- content_type.entry() raises PermissionError if entry_uid is None, or if the content type UID is None, as it is after stack.content_type() with no argument.
- Every method except fetch and variants returns the same Entry, so calls chain in any order and fetch sends the request.
Warning content_type.entry('') does not raise. The factory rejects None only, so an empty string builds a request URL that ends in /entries/ with no entry UID. Check that a UID variable is non-empty before you pass it.
Class-Level Notes
Two parameter stores, and the inherited one wins.
- param, version, include_fallback, include_branch, and include_embedded_items write the entry's own parameter store.
- The methods Entry inherits from EntryQueryable write a second store: locale, only, excepts, include_reference, include_content_type, include_reference_content_type_uid, include_metadata, asset_fields, and add_param.
- fetch merges the second store over the first. On a shared key the inherited value wins, whatever order you call the methods in.
Flags are one-way.
- The include_ methods each write a fixed value under a fixed key, so a second call changes nothing.
- No method on Entry deletes a parameter. Build a fresh entry from content_type.entry('<ENTRY_UID>') to send a request without one.
The environment lives on the Stack.
- Stack sends the environment as a request header, and fetch copies that header into the environment query parameter.
- environment and remove_environment change that header on the Stack, so the change reaches every object that the Stack creates.
Known issue environment and remove_environment change the environment for every later request from the same Stack, not for this entry alone. Create one Stack per environment instead.
Live preview changes what fetch returns.
- When you create the Stack with a live_preview dictionary, fetch merges the preview entry into the published entry and returns a list instead of a dictionary.
- The fetch method page lists the conditions under which that merge raises, and the shape of the list it returns.
Rate limiting and retry.
- This SDK retries 408 and 429 responses automatically. The default retry_strategy sends the initial request plus up to five retries, with no delay between them, because its backoff_factor is 0.
- Pass your own retry_strategy to Stack with a non-zero backoff factor if you expect to hit 429.
Additional Resource Implement Retry Mechanism with Python Delivery SDK covers the retry_strategy parameters and backoff configuration.
Capability Matrix
| Capability | Supported | Notes / Alternative |
|---|---|---|
| Read several entries in one call | No | Use the Query object that content_type.query() returns. |
| Read an earlier version of an entry | No | The Delivery API serves the latest published version. Use the Content Management API. |
| Keep or drop several base fields with one call | No | only and excepts hold one field UID each. Pass a list through add_param. |
| Scope the environment to one entry | No | environment changes the whole Stack. Create one Stack per environment. |
| Remove a parameter after you set it | No | Build a fresh entry from content_type.entry('<ENTRY_UID>'). |
Method Index
The groups below follow what you are trying to do. Every method is available on any Entry from content_type.entry('<ENTRY_UID>').
Read the entry. Available on any Entry, as the last call in the chain.
| Method Name | Returns | Description |
|---|---|---|
| fetch | The requested entry. | Reads one entry by its UID. |
Choose what the request reads. Available on any Entry, before fetch.
| Method Name | Returns | Description |
|---|---|---|
| locale | The same entry, for chaining. | Sets the locale to read. |
| include_fallback | The same entry, for chaining. | Returns fallback locale content when a localization is missing. |
| environment | The same entry, for chaining. | Sets the environment header on the Stack. |
| remove_environment | The same entry, for chaining. | Deletes the environment header from the Stack. |
| version | The same entry, for chaining. | Sends a version number with the request. |
Shape the response. Available on any Entry, before fetch.
| Method Name | Returns | Description |
|---|---|---|
| only | The same entry, for chaining. | Keeps one top-level field in the response. |
| excepts | The same entry, for chaining. | Leaves one top-level field out of the response. |
| include_reference | The same entry, for chaining. | Returns referenced entries in full instead of as UIDs. |
| include_reference_content_type_uid | The same entry, for chaining. | Asks for the content type UID of each referenced entry. |
| include_content_type | The same entry, for chaining. | Asks for the content type with the entry. |
| include_embedded_items | The same entry, for chaining. | Returns items embedded in rich text fields. |
| include_metadata | The same entry, for chaining. | Adds the entry metadata to the response. |
| include_branch | The same entry, for chaining. | Adds the _branch key to the response. |
| asset_fields | The same entry, for chaining. | Adds extra field groups to embedded assets. |
Send a parameter the SDK has no method for. Available on any Entry. The two methods write different stores.
| Method Name | Returns | Description |
|---|---|---|
| param | The same entry, for chaining. | Adds a query parameter, converting the value to a string. |
| add_param | The same entry, for chaining. | Adds a query parameter to the inherited store, unconverted. |
Move to the variants of the entry. Available on any Entry, and returns a different class.
| Method Name | Returns | Description |
|---|---|---|
| variants | A new Variants for the given variant UIDs. | Reads this entry with the content of entry variants. |
Class-Level Snippet
This snippet reads one entry in French, reads the fallback locale when French has no published version, and resolves two reference fields.
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>') \
.entry('<ENTRY_UID>') \
.locale('fr-fr') \
.include_fallback() \
.include_reference(['author', 'categories']) \
.fetch()
except Exception as error:
# Raised only for network failures (timeout, DNS error, dropped connection)
print('Request failed:', error)
else:
if 'error_code' in result:
# The Delivery API rejected the request and returned the error body
print('Delivery API error:', result['error_code'], result['error_message'])
else:
entry = result['entry']
print(entry['uid'], entry['title'])Methods
Each method of the Entry class has its own section below, with its parameters, validation rules, behavior, and examples.
add_param
add_param adds one query parameter that the SDK has no method for.
| Name | Type | Description |
|---|---|---|
| key (required) | str | Query parameter name. |
| value (required) | str | Value to send for that parameter. |
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation. When key or value is None, add_param records nothing, raises nothing, and returns the entry.
- add_param keeps the value as given, without converting it to a string.
- Calling add_param() with fewer than two arguments raises TypeError, because add_param takes key and value as positional parameters with no default.
- Errors that do occur come from the fetch() call that follows, not from add_param().
- fetch() raises an exception only for network failures (timeout, DNS error, dropped connection).
- An API-level rejection returns as a normal result with an error_code key. It does not raise an exception.
- Check the result for an error_code key even inside a try block.
Additional Resource Refer to Delivery API Errors for the full error code list.
Behavior
- Client-side only. add_param stores the pair and makes no request. The fetch method sends it.
- A second call with the same key replaces the value.
- A list value sends one pair per item, because the fetch method encodes repeated keys. The annotation names str, and a list works the same way.
- add_param writes the parameter store that Entry inherits from EntryQueryable. The fetch method merges that store over the entry's own store. On a shared key, this value wins over the value from the param method, in any call order.
- The param method writes the entry's own store and converts the value to a string. Use add_param when you need a list value or need to override a value another method set.
Example
Basic usage: resolve taxonomy terms
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').add_param('include_taxonomy_terms', 'true').fetch()
except Exception as error:
# Raised only for network failures (timeout, DNS error, dropped connection)
print('Request failed:', error)
else:
if 'error_code' in result:
# The Delivery API rejected the request and returned the error body
print('Delivery API error:', result['error_code'], result['error_message'])
else:
print(result['entry']['title'])List value: keep two top-level fields
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
# A list sends one only[BASE][] pair per item.
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').add_param('only[BASE][]', ['title', 'url']).fetch()
print(result['entry'])
except Exception as error:
print('Request failed:', error)asset_fields
asset_fields asks the API to add extra field groups to each asset embedded in the entry.
| Name | Type | Description |
|---|---|---|
| field_names (required) | str | list[str] | Asset field group names. Pass them as separate arguments. |
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation of the names. asset_fields converts each value with str() and keeps it, so a misspelled name reaches the request.
- A list or tuple argument contributes each of its items.
- A call with no arguments changes nothing and raises nothing.
- Errors that do occur come from the fetch() call that follows, not from asset_fields().
- fetch() raises an exception only for network failures (timeout, DNS error, dropped connection).
- An API-level rejection returns as a normal result with an error_code key. It does not raise an exception.
- Check the result for an error_code key even inside a try block.
Additional Resource Refer to Delivery API Errors for the full error code list.
Behavior
- Client-side only. asset_fields adds each name to the asset_fields[] query parameter and makes no request. The fetch method sends one asset_fields[] pair per name.
- Calls add up. A second call appends its names to the ones already stored, and a repeated name goes out twice.
- The SDK documents four field group names: user_defined_fields, embedded_metadata, ai_generated_metadata, and visual_markups.
- visual_markups returns the hotspot and bounding-box annotations of each embedded asset under the visual_markups key. See the asset_fields[] parameter of the Get a single entry request.
- asset_fields writes the parameter store that Entry inherits from EntryQueryable. The fetch method merges that store over the entry's own store. On a shared key, this value wins over the value from the param method, in any call order.
Example
Basic usage: add one field group
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').asset_fields('visual_markups').fetch()
except Exception as error:
# Raised only for network failures (timeout, DNS error, dropped connection)
print('Request failed:', error)
else:
if 'error_code' in result:
# The Delivery API rejected the request and returned the error body
print('Delivery API error:', result['error_code'], result['error_message'])
else:
print(result['entry']['title'])Several field groups: pass names as separate arguments, or a list
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
# Calls add up. This request sends three asset_fields[] values.
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').asset_fields('user_defined_fields', 'visual_markups').asset_fields(['embedded_metadata']).fetch()
print(result['entry'])
except Exception as error:
print('Request failed:', error)environment
environment sets the environment the request reads published content from.
| Name | Type | Description |
|---|---|---|
| environment (required) | str | Name of the environment to read from. |
Returns: Entry. The same entry, for chaining.
Validation
- environment raises KeyError if environment is None, because the SDK needs a value to write into the environment request header.
- There is no other client-side validation. An empty string or an environment name the stack does not have reaches the request as given.
- Calling environment() without an argument raises TypeError, because environment is a required positional parameter.
- Errors that do occur come from the fetch() call that follows, not from environment().
- fetch() raises an exception only for network failures (timeout, DNS error, dropped connection).
- An API-level rejection returns as a normal result with an error_code key. It does not raise an exception.
- Check the result for an error_code key even inside a try block.
Additional Resource Refer to Delivery API Errors for the full error code list.
Behavior
- Client-side only. environment writes the environment request header and makes no request.
- The fetch method copies that header into the environment query parameter. See the environment parameter of the Get a single entry request.
- The header lives on the Stack, not on the entry. Every object that the same Stack creates reads the same header dictionary.
Known issue environment changes the environment for every later request from the same Stack, including queries, assets, and entries you built earlier. Create one Stack per environment instead of calling environment to switch between them.
Example
Basic usage: read an entry from another environment
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').environment('staging').fetch()
except Exception as error:
# Raised only for network failures (timeout, DNS error, dropped connection)
print('Request failed:', error)
else:
if 'error_code' in result:
# The Delivery API rejected the request and returned the error body
print('Delivery API error:', result['error_code'], result['error_message'])
else:
print(result['entry']['title'])Separate stacks: keep each environment apart
import contentstack
production = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', 'production')
staging = contentstack.Stack('<API_KEY>', '<STAGING_DELIVERY_TOKEN>', 'staging')
try:
# Each Stack keeps its own environment header, so neither request affects the other.
live = production.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').fetch()
draft = staging.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').fetch()
print(live.get('entry'), draft.get('entry'))
except Exception as error:
print('Request failed:', error)excepts
excepts removes one top-level field from each entry in the response.
| Name | Type | Description |
|---|---|---|
| field_uid (required) | str | UID of the top-level field to leave out. |
Returns: Entry. The same entry, for chaining.
Validation
- excepts accepts one field UID as a string. It raises KeyError if field_uid is any other non-null type, such as a list, because excepts stores a single string under the except[BASE][] key.
- A None value records nothing and raises nothing, so the response carries every field.
- excepts does not check that the field exists. An unknown field UID reaches the request as given.
- Calling excepts() without an argument raises TypeError, because field_uid is a required positional parameter.
- Errors that do occur come from the fetch() call that follows, not from excepts().
- fetch() raises an exception only for network failures (timeout, DNS error, dropped connection).
- An API-level rejection returns as a normal result with an error_code key. It does not raise an exception.
- Check the result for an error_code key even inside a try block.
Additional Resource Refer to Delivery API Errors for the full error code list.
Behavior
- Client-side only. excepts writes the except[BASE][] query parameter and makes no request. The fetch method sends it.
- A second call replaces the first field. excepts holds one field UID at a time.
- excepts writes the parameter store that Entry inherits from EntryQueryable. The fetch method merges that store over the entry's own store. On a shared key, this value wins over the value from the param method, in any call order.
- BASE stands for the top-level fields of the content type schema. See the Exclude operator section of the API reference.
Limitations
- Does not take more than one field. To leave out several fields, pass a list under the same key through the add_param method, for example add_param('except[BASE][]', ['title', 'url']). The fetch method sends one except[BASE][] pair per list item.
- Does not apply to the fields of a referenced entry. The API takes except[<reference_field_uid>][] for those. Send it through the add_param method together with the include_reference method.
Example
Basic usage: leave the body field out
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').excepts('body').fetch()
except Exception as error:
# Raised only for network failures (timeout, DNS error, dropped connection)
print('Request failed:', error)
else:
if 'error_code' in result:
# The Delivery API rejected the request and returned the error body
print('Delivery API error:', result['error_code'], result['error_message'])
else:
print(result['entry']['title'])Several fields: pass a list through add_param
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').add_param('except[BASE][]', ['title', 'url']).fetch()
print(result['entry'])
except Exception as error:
print('Request failed:', error)fetch
fetch reads one published entry by its UID and returns the response body.
This method takes no parameters. It reads the content type UID, the entry UID, and every chained parameter from the instance.
Returns: dict or list. The requested entry.
Validation
- fetch does not check the UIDs. The content_type.entry() call rejects None only. An empty entry UID therefore reaches fetch, and the request URL ends in /entries/ with no UID.
- When the Stack carries a live_preview dictionary, fetch can raise before or after the request.
- It raises KeyError if the dictionary has no enable key, because fetch reads that key directly.
- It raises ValueError if no preview entry is available to merge, because the merge needs both the published and the preview entry. See the Known issue below.
- fetch raises an exception only for network failures (timeout, DNS error, dropped connection).
- An API-level rejection returns as a normal result with an error_code key. It does not raise an exception.
- Check the result for an error_code key even inside a try block.
Additional Resource Refer to Delivery API Errors for the full error code list.
Behavior
- Each call sends one GET /content_types/{content_type_uid}/entries/{entry_uid} request. See the Get a single entry request.
- fetch returns the whole response body as a dictionary. Read the entry from its entry key.
- fetch builds the query string in three steps.
- It copies the environment request header into the environment query parameter when the header exists.
- It merges the parameters from the inherited methods, such as locale and only, over the entry's own parameters from methods such as param and version. On a shared key, the inherited value wins.
- It encodes a list value as one key=value pair per item.
- The entry keeps every chained parameter, so a second fetch on the same instance sends the same request again.
- With live preview, fetch returns a list instead of a dictionary.
- When enable is true and the content_type_uid in the live preview dictionary matches this entry's content type, fetch first requests the preview entry. It sends the authorization header when the dictionary holds management_token, and the preview_token header otherwise.
- fetch then merges the preview entry into the published entry by uid, field by field, and returns the merged entries as a list.
- When the preview entry has a different uid from the requested entry, the list holds both entries. Find the one you asked for by its uid.
Known issue When the Stack carries a live_preview dictionary, fetch raises ValueError until a live preview request has returned a preview entry. After that, fetch merges the stored preview entry into every later result from the same Stack, for any content type. Read published content from a second Stack created without live_preview.
Limitations
- Does not read more than one entry. Use the find method on the Query class to read several entries in one request.
- Does not read a variant of the entry. Use the variants method instead.
Example
Basic usage: read one entry by UID
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').fetch()
except Exception as error:
# Raised only for network failures (timeout, DNS error, dropped connection)
print('Request failed:', error)
else:
if 'error_code' in result:
# The Delivery API rejected the request and returned the error body
print('Delivery API error:', result['error_code'], result['error_message'])
else:
print(result['entry']['uid'], result['entry']['title'])Chained parameters: locale, fallback, references, and embedded items
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>') \
.entry('<ENTRY_UID>') \
.locale('fr-fr') \
.include_fallback() \
.include_reference(['author', 'categories']) \
.include_embedded_items() \
.fetch()
print(result.get('entry'))
except Exception as error:
print('Request failed:', error)Edge case: live preview returns a list
import contentstack
stack = contentstack.Stack(
'<API_KEY>',
'<DELIVERY_TOKEN>',
'<ENVIRONMENT>',
live_preview={'enable': True, 'preview_token': '<PREVIEW_TOKEN>'},
)
stack.live_preview_query(live_preview_query={
'live_preview': '<LIVE_PREVIEW_HASH>',
'content_type_uid': '<CONTENT_TYPE_UID>',
'entry_uid': '<ENTRY_UID>',
})
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').fetch()
except ValueError as error:
# Fires when no preview entry is available to merge
print('Live preview data is incomplete:', error)
else:
if isinstance(result, dict):
# An API rejection still arrives as the error body
print(result.get('error_code'), result.get('error_message'))
else:
# A live preview result is a list of merged entries. Pick the entry by its UID.
entry = next((item for item in result if item.get('uid') == '<ENTRY_UID>'), None)
print(entry)include_branch
include_branch asks the API to add the _branch key, which names the branch the entry belongs to, to the response.
This method takes no parameters.
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation. include_branch cannot fail.
- Errors that do occur come from the fetch() call that follows, not from include_branch().
- fetch() raises an exception only for network failures (timeout, DNS error, dropped connection).
- An API-level rejection returns as a normal result with an error_code key. It does not raise an exception.
- Check the result for an error_code key even inside a try block.
Additional Resource Refer to Delivery API Errors for the full error code list.
Behavior
- Client-side only. include_branch sets the include_branch query parameter to 'true' in the entry's own parameter store and makes no request. The fetch method sends it.
- The API adds the _branch key with the unique ID of the branch. See the include_branch parameter of the Get a single entry request.
- include_branch does not choose the branch. The branch argument of Stack sets the branch request header that does.
- A second call changes nothing. The SDK writes the same key again.
Example
Basic usage: read the branch of an entry
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>', branch='development')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').include_branch().fetch()
except Exception as error:
# Raised only for network failures (timeout, DNS error, dropped connection)
print('Request failed:', error)
else:
if 'error_code' in result:
# The Delivery API rejected the request and returned the error body
print('Delivery API error:', result['error_code'], result['error_message'])
else:
print(result['entry'].get('_branch'))include_content_type
include_content_type asks the API to return the content type of the entry along with the response.
This method takes no parameters.
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation. include_content_type cannot fail.
- Errors that do occur come from the fetch() call that follows, not from include_content_type().
- fetch() raises an exception only for network failures (timeout, DNS error, dropped connection).
- An API-level rejection returns as a normal result with an error_code key. It does not raise an exception.
- Check the result for an error_code key even inside a try block.
Additional Resource Refer to Delivery API Errors for the full error code list.
Behavior
- Client-side only. include_content_type writes two query parameters and makes no request. The fetch method sends both.
- include_content_type set to 'true'.
- include_global_field_schema set to 'true', so the content type schema carries the schema of each global field it uses. See the include_global_field_schema parameter of the Get a single content type request.
- A second call changes nothing. The SDK writes the same two keys again.
- include_content_type writes the parameter store that Entry inherits from EntryQueryable. The fetch method merges that store over the entry's own store. On a shared key, this value wins over the value from the param method, in any call order.
Example
Basic usage: read the content type with the entry
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').include_content_type().fetch()
except Exception as error:
# Raised only for network failures (timeout, DNS error, dropped connection)
print('Request failed:', error)
else:
if 'error_code' in result:
# The Delivery API rejected the request and returned the error body
print('Delivery API error:', result['error_code'], result['error_message'])
else:
print(result['entry']['title'])Read the content type from the response
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').include_content_type().fetch()
print(result.get('content_type'))
except Exception as error:
print('Request failed:', error)include_embedded_items
include_embedded_items asks the API to return the entries and assets embedded in the rich text fields of the entry.
This method takes no parameters.
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation. include_embedded_items cannot fail.
- Errors that do occur come from the fetch() call that follows, not from include_embedded_items().
- fetch() raises an exception only for network failures (timeout, DNS error, dropped connection).
- An API-level rejection returns as a normal result with an error_code key. It does not raise an exception.
- Check the result for an error_code key even inside a try block.
Additional Resource Refer to Delivery API Errors for the full error code list.
Behavior
- Client-side only. include_embedded_items sets the include_embedded_items[] query parameter to BASE in the entry's own parameter store and makes no request. The fetch method sends it.
- With BASE, the API returns the first level of entries and assets embedded in the Rich Text Editor field, under the _embedded_items key. See the Get information on embedded RTE objects request.
- A second call changes nothing. The SDK writes the same key again.
Limitations
- Does not return items embedded inside embedded items. Send include_embedded_items[] as RECURSIVE through the add_param method instead, and embedded_items_depth to set the number of levels. The API caps the depth at 5. A value set through add_param wins over the BASE value that include_embedded_items writes.
Example
Basic usage: read the embedded items of an entry
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').include_embedded_items().fetch()
except Exception as error:
# Raised only for network failures (timeout, DNS error, dropped connection)
print('Request failed:', error)
else:
if 'error_code' in result:
# The Delivery API rejected the request and returned the error body
print('Delivery API error:', result['error_code'], result['error_message'])
else:
print(result['entry'].get('_embedded_items'))Nested embedded items: send RECURSIVE through add_param
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>') \
.entry('<ENTRY_UID>') \
.add_param('include_embedded_items[]', 'RECURSIVE') \
.add_param('embedded_items_depth', '3') \
.fetch()
print(result['entry'].get('_embedded_items'))
except Exception as error:
print('Request failed:', error)include_fallback
include_fallback asks the API to return the fallback locale content when the entry has no published content in the requested locale.
This method takes no parameters.
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation. include_fallback cannot fail.
- Errors that do occur come from the fetch() call that follows, not from include_fallback().
- fetch() raises an exception only for network failures (timeout, DNS error, dropped connection).
- An API-level rejection returns as a normal result with an error_code key. It does not raise an exception.
- Check the result for an error_code key even inside a try block.
Additional Resource Refer to Delivery API Errors for the full error code list.
Behavior
- Client-side only. include_fallback sets the include_fallback query parameter to 'true' in the entry's own parameter store and makes no request. The fetch method sends it.
- include_fallback prints a line to standard output on every call. The SDK offers no setting to turn it off.
- The API returns the published content of the fallback locale when the locale you named has none. See the include_fallback parameter of the Get a single entry request.
- Chain the locale method to name the locale the fallback applies to.
- A second call changes nothing. The SDK writes the same key again.
Example
Basic usage: read French content, or the fallback locale
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').locale('fr-fr').include_fallback().fetch()
except Exception as error:
# Raised only for network failures (timeout, DNS error, dropped connection)
print('Request failed:', error)
else:
if 'error_code' in result:
# The Delivery API rejected the request and returned the error body
print('Delivery API error:', result['error_code'], result['error_message'])
else:
# The locale key shows which locale the content came from.
print(result['entry']['title'], result['entry'].get('locale'))include_metadata
include_metadata asks the API to add the entry's metadata to the response.
This method takes no parameters.
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation. include_metadata cannot fail.
- Errors that do occur come from the fetch() call that follows, not from include_metadata().
- fetch() raises an exception only for network failures (timeout, DNS error, dropped connection).
- An API-level rejection returns as a normal result with an error_code key. It does not raise an exception.
- Check the result for an error_code key even inside a try block.
Additional Resource Refer to Delivery API Errors for the full error code list.
Behavior
- Client-side only. include_metadata sets the include_metadata query parameter to 'true' and makes no request. The fetch method sends it.
- The API returns the metadata under the _metadata key of the entry, with one key per extension UID. See the Get a single entry request.
- A second call changes nothing. The SDK writes the same key again.
- include_metadata writes the parameter store that Entry inherits from EntryQueryable. The fetch method merges that store over the entry's own store. On a shared key, this value wins over the value from the param method, in any call order.
Example
Basic usage: read the entry with its metadata
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').include_metadata().fetch()
except Exception as error:
# Raised only for network failures (timeout, DNS error, dropped connection)
print('Request failed:', error)
else:
if 'error_code' in result:
# The Delivery API rejected the request and returned the error body
print('Delivery API error:', result['error_code'], result['error_message'])
else:
print(result['entry']['title'])Read the metadata key
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').include_metadata().fetch()
print(result['entry'].get('_metadata'))
except Exception as error:
print('Request failed:', error)include_reference
include_reference asks the API to return the entries in the named reference fields in full, instead of as UIDs.
| Name | Type | Description |
|---|---|---|
| field_uid (required) | str | list[str] | Reference field UID, or a list of them, to resolve. |
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation of the field UID. include_reference does not check that the field exists or that it is a reference field.
- A value that is not a str or a list, such as None or a tuple, records nothing and raises nothing. The request then goes out without include[], and every reference field holds UIDs only.
- Calling include_reference() without an argument raises TypeError, because field_uid is a required positional parameter.
- Errors that do occur come from the fetch() call that follows, not from include_reference().
- fetch() raises an exception only for network failures (timeout, DNS error, dropped connection).
- An API-level rejection returns as a normal result with an error_code key. It does not raise an exception.
- Check the result for an error_code key even inside a try block.
Additional Resource Refer to Delivery API Errors for the full error code list.
Behavior
- Client-side only. include_reference writes the include[] query parameter and makes no request. The fetch method sends it.
- A list sends one include[] pair per item.
- A second call replaces the first value. It does not add to it, so pass every field in one list.
- include_reference writes the parameter store that Entry inherits from EntryQueryable. The fetch method merges that store over the entry's own store. On a shared key, this value wins over the value from the param method, in any call order.
- Without include_reference, a reference field holds only the UIDs of the referenced entries. See the Include Reference section of the API reference.
- To keep only some fields of a referenced entry, send only[<reference_field_uid>][] through the add_param method.
Example
Basic usage: resolve one reference field
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').include_reference('author').fetch()
except Exception as error:
# Raised only for network failures (timeout, DNS error, dropped connection)
print('Request failed:', error)
else:
if 'error_code' in result:
# The Delivery API rejected the request and returned the error body
print('Delivery API error:', result['error_code'], result['error_message'])
else:
print(result['entry']['title'])Several fields: pass a list
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').include_reference(['author', 'categories']).fetch()
print(result['entry'])
except Exception as error:
print('Request failed:', error)include_reference_content_type_uid
include_reference_content_type_uid asks the API to add the content type UID to each referenced entry in the response.
This method takes no parameters.
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation. include_reference_content_type_uid cannot fail.
- Errors that do occur come from the fetch() call that follows, not from include_reference_content_type_uid().
- fetch() raises an exception only for network failures (timeout, DNS error, dropped connection).
- An API-level rejection returns as a normal result with an error_code key. It does not raise an exception.
- Check the result for an error_code key even inside a try block.
Additional Resource Refer to Delivery API Errors for the full error code list.
Behavior
- Client-side only. include_reference_content_type_uid sets the include_reference_content_type_uid query parameter to 'true' and makes no request. The fetch method sends it.
- A second call changes nothing. The SDK writes the same key again.
- include_reference_content_type_uid writes the parameter store that Entry inherits from EntryQueryable. The fetch method merges that store over the entry's own store. On a shared key, this value wins over the value from the param method, in any call order.
- Chain the include_reference method as well when you need the referenced entries in full.
Example
Basic usage: resolve a reference and its content type UID
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').include_reference('author').include_reference_content_type_uid().fetch()
except Exception as error:
# Raised only for network failures (timeout, DNS error, dropped connection)
print('Request failed:', error)
else:
if 'error_code' in result:
# The Delivery API rejected the request and returned the error body
print('Delivery API error:', result['error_code'], result['error_message'])
else:
print(result['entry']['title'])locale
locale sets the locale the entry reads, so the response carries content published in that locale.
| Name | Type | Description |
|---|---|---|
| locale (required) | str | Locale code to read, for example fr-fr. |
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation. locale keeps the value as given, so an empty string or a code the stack does not have reaches the request. A None value reaches the request as the text None.
- Calling locale() without an argument raises TypeError, because locale is a required positional parameter.
- Errors that do occur come from the fetch() call that follows, not from locale().
- fetch() raises an exception only for network failures (timeout, DNS error, dropped connection).
- An API-level rejection returns as a normal result with an error_code key. It does not raise an exception.
- Check the result for an error_code key even inside a try block.
Additional Resource Refer to Delivery API Errors for the full error code list.
Behavior
- Client-side only. locale writes the locale query parameter and makes no request. The fetch method sends it.
- A second call replaces the first value.
- locale writes the parameter store that Entry inherits from EntryQueryable. The fetch method merges that store over the entry's own store. On a shared key, this value wins over the value from the param method, in any call order.
- The Delivery API returns only content published in the locale you name. See the locale parameter of the Get a single entry request.
- When the content has no published version in that locale, chain the include_fallback method to read the fallback locale instead.
Example
Basic usage: read content in French
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').locale('fr-fr').fetch()
except Exception as error:
# Raised only for network failures (timeout, DNS error, dropped connection)
print('Request failed:', error)
else:
if 'error_code' in result:
# The Delivery API rejected the request and returned the error body
print('Delivery API error:', result['error_code'], result['error_message'])
else:
print(result['entry']['title'])Locale with fallback: read the fallback locale when French has no published version
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').locale('fr-fr').include_fallback().fetch()
print(result['entry'])
except Exception as error:
print('Request failed:', error)only
only limits each entry in the response to one top-level field.
| Name | Type | Description |
|---|---|---|
| field_uid (required) | str | UID of the top-level field to keep. |
Returns: Entry. The same entry, for chaining.
Validation
- only accepts one field UID as a string. It raises KeyError if field_uid is any other non-null type, such as a list, because only stores a single string under the only[BASE][] key.
- A None value records nothing and raises nothing, so the response carries every field.
- only does not check that the field exists. An unknown field UID reaches the request as given.
- Calling only() without an argument raises TypeError, because field_uid is a required positional parameter.
- Errors that do occur come from the fetch() call that follows, not from only().
- fetch() raises an exception only for network failures (timeout, DNS error, dropped connection).
- An API-level rejection returns as a normal result with an error_code key. It does not raise an exception.
- Check the result for an error_code key even inside a try block.
Additional Resource Refer to Delivery API Errors for the full error code list.
Behavior
- Client-side only. only writes the only[BASE][] query parameter and makes no request. The fetch method sends it.
- A second call replaces the first field. only holds one field UID at a time.
- only writes the parameter store that Entry inherits from EntryQueryable. The fetch method merges that store over the entry's own store. On a shared key, this value wins over the value from the param method, in any call order.
- BASE stands for the top-level fields of the content type schema. See the Only operator section of the API reference.
Limitations
- Does not take more than one field. To keep several fields, pass a list under the same key through the add_param method, for example add_param('only[BASE][]', ['title', 'url']). The fetch method sends one only[BASE][] pair per list item.
- Does not apply to the fields of a referenced entry. The API takes only[<reference_field_uid>][] for those. Send it through the add_param method together with the include_reference method.
Example
Basic usage: keep only the title field
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').only('title').fetch()
except Exception as error:
# Raised only for network failures (timeout, DNS error, dropped connection)
print('Request failed:', error)
else:
if 'error_code' in result:
# The Delivery API rejected the request and returned the error body
print('Delivery API error:', result['error_code'], result['error_message'])
else:
print(result['entry']['title'])Several fields: pass a list through add_param
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').add_param('only[BASE][]', ['title', 'url']).fetch()
print(result['entry'])
except Exception as error:
print('Request failed:', error)param
param adds one query parameter to the request, converting the value to a string.
| Name | Type | Description |
|---|---|---|
| key (required) | str | Query parameter name. |
| value (required) | Any | Value to send. param converts it to a string. |
Returns: Entry. The same entry, for chaining.
Validation
- param raises ValueError if either argument is None and key is not a string, because the SDK cannot build a parameter name from it. param(None, 'true') raises for that reason.
- A string key with a None value does not raise. param converts None with str() and sends the text None as the value.
- A non-string key, such as an integer, with a non-null value does not raise. The request carries the key as text.
- Calling param() with fewer than two arguments raises TypeError, because param takes key and value as positional parameters with no default.
- Errors that do occur come from the fetch() call that follows, not from param().
- fetch() raises an exception only for network failures (timeout, DNS error, dropped connection).
- An API-level rejection returns as a normal result with an error_code key. It does not raise an exception.
- Check the result for an error_code key even inside a try block.
Additional Resource Refer to Delivery API Errors for the full error code list.
Behavior
- Client-side only. param writes the pair to the entry's own parameter store and makes no request. The fetch method sends it.
- param converts every non-string value with str(). A list therefore goes out as its Python text, such as ['title', 'url'], rather than as repeated keys. Use the add_param method for a list value.
- A second call with the same key replaces the value.
- The methods that Entry inherits from EntryQueryable, such as locale and add_param, write a second store that the fetch method merges over this one. On a shared key, the inherited value wins, so param('locale', 'en-us') never overrides locale('fr-fr').
Example
Basic usage: resolve taxonomy terms
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').param('include_taxonomy_terms', 'true').fetch()
except Exception as error:
# Raised only for network failures (timeout, DNS error, dropped connection)
print('Request failed:', error)
else:
if 'error_code' in result:
# The Delivery API rejected the request and returned the error body
print('Delivery API error:', result['error_code'], result['error_message'])
else:
print(result['entry'].get('taxonomies'))Edge case: an inherited method wins on a shared key
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
# The request sends locale=fr-fr. locale() wins over param('locale', ...) in any call order.
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').locale('fr-fr').param('locale', 'en-us').fetch()
print(result['entry'].get('locale'))
except Exception as error:
print('Request failed:', error)remove_environment
remove_environment deletes the environment request header, so the request carries no environment.
This method takes no parameters. It reads the request headers of the Stack that built the entry.
Returns: Entry. The same entry, for chaining.
Validation
- There is no client-side validation. When the header is already absent, remove_environment changes nothing and raises nothing.
- Errors that do occur come from the fetch() call that follows, not from remove_environment().
- fetch() raises an exception only for network failures (timeout, DNS error, dropped connection).
- An API-level rejection returns as a normal result with an error_code key. It does not raise an exception.
- Check the result for an error_code key even inside a try block.
Additional Resource Refer to Delivery API Errors for the full error code list.
Behavior
- Client-side only. remove_environment deletes the environment key from the headers of the Stack and makes no request.
- Without the header, the fetch method sends no environment query parameter.
- The environment method writes the header back.
Known issue remove_environment removes the environment for every later request from the same Stack, including queries, assets, and entries you built earlier. Create a separate Stack for requests that need different environment settings.
Limitations
- Does not clear an environment that an earlier fetch call already copied into the entry's parameters. The next fetch from that same entry still sends it. Call remove_environment before the first fetch, or build a fresh entry instead.
Example
Basic usage: send a request without an environment
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').remove_environment().fetch()
except Exception as error:
# Raised only for network failures (timeout, DNS error, dropped connection)
print('Request failed:', error)
else:
if 'error_code' in result:
# The Delivery API rejected the request and returned the error body
print('Delivery API error:', result['error_code'], result['error_message'])
else:
print(result['entry']['title'])variants
variants returns a Variants object that reads this entry with the content of one or more entry variants applied.
| Name | Type | Description |
|---|---|---|
| variant_uid (required) | str | list[str] | Variant UID, or a list of them, to apply. |
| branch | str | Branch to send the variant request to. |
| params | dict | Query parameters to send with the variant request. |
Returns: Variants. A new Variants for the given variant UIDs.
Validation
- There is no client-side validation. variants builds the object and makes no request, so every check happens on the fetch or find call that follows.
- Pass variant_uid as a str or a list. A list that holds a non-string item raises TypeError on that later call, because the SDK joins the list with commas.
- Calling variants() without an argument raises TypeError, because variant_uid is a required positional parameter.
- Errors from the request itself come from the fetch or find call. Those calls raise only for network failures and return an API-level rejection as a normal result with an error_code key.
Additional Resource Refer to Delivery API Errors for the full error code list.
Known issue A variant_uid of any other type, such as a tuple or None, sends no variant header. The request then returns the base entry with no error. Convert a tuple to a list before you pass it.
Behavior
- Client-side only. variants returns a new Variants object that holds the content type UID, the entry UID, and the three arguments. It makes no request.
- The new object does not carry the parameters chained on this entry. A locale or param call before variants does not reach the variant request. Pass those values in params instead.
- The SDK sends the variant UIDs in the x-cs-variant-uid request header, and joins a list with commas. By default the API accepts up to 5 variant UIDs or aliases, and the first one takes priority on the base entry fields. See the Get single entry variant request.
- branch replaces the branch request header for the variant request only. The SDK puts the previous value back when the response arrives.
- The Variants object keeps the params dictionary you pass, not a copy. Later fetch and find calls on it add their own parameters to that same dictionary.
- See the Entry Variants class page for what the returned object supports.
Example
Basic usage: read an entry with one variant applied
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').variants('<VARIANT_UID>').fetch()
except Exception as error:
# Raised only for network failures (timeout, DNS error, dropped connection)
print('Request failed:', error)
else:
if 'error_code' in result:
# The Delivery API rejected the request and returned the error body
print('Delivery API error:', result['error_code'], result['error_message'])
else:
print(result['entry']['title'])All parameters: several variants, a branch, and query parameters
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
# The first variant UID takes priority on the base entry fields.
result = stack.content_type('<CONTENT_TYPE_UID>') \
.entry('<ENTRY_UID>') \
.variants(['<VARIANT_UID>', '<SECOND_VARIANT_UID>'], branch='development', params={'locale': 'fr-fr'}) \
.fetch()
print(result.get('entry'))
except Exception as error:
print('Request failed:', error)version
version adds a version query parameter that names a version number of the entry.
| Name | Type | Description |
|---|---|---|
| version (required) | int | Version number of the entry to request. |
Returns: Entry. The same entry, for chaining.
Validation
- version raises KeyError if version is None, because the SDK needs a value to send.
- There is no other client-side validation. A string, a zero, or a negative number reaches the request as given.
- Calling version() without an argument raises TypeError, because version is a required positional parameter.
- Errors that do occur come from the fetch() call that follows, not from version().
- fetch() raises an exception only for network failures (timeout, DNS error, dropped connection).
- An API-level rejection returns as a normal result with an error_code key. It does not raise an exception.
- Check the result for an error_code key even inside a try block.
Additional Resource Refer to Delivery API Errors for the full error code list.
Behavior
- Client-side only. version writes the version query parameter to the entry's own parameter store and makes no request. The fetch method sends it.
- A second call replaces the first value.
- The Delivery API returns only the latest published version of an entry and lists no version parameter for that request. See the Get a single entry request.
Known issue version does not return an earlier version. The response carries the latest published version whatever number you pass. Use the Get a single entry request of the Content Management API to read a specific version.
Example
Basic usage: send a version number with the request
import contentstack
stack = contentstack.Stack('<API_KEY>', '<DELIVERY_TOKEN>', '<ENVIRONMENT>')
try:
result = stack.content_type('<CONTENT_TYPE_UID>').entry('<ENTRY_UID>').version(4).fetch()
except Exception as error:
# Raised only for network failures (timeout, DNS error, dropped connection)
print('Request failed:', error)
else:
if 'error_code' in result:
# The Delivery API rejected the request and returned the error body
print('Delivery API error:', result['error_code'], result['error_message'])
else:
# The Delivery API returns the latest published version.
print(result['entry'].get('_version'))