Contentful Management API SDK
=============================
.. image:: https://travis-ci.org/contentful/contentful-management.py.svg?branch=master
:target: https://travis-ci.org/contentful/contentful-management.py
`Contentful <https://www.contentful.com>`_ provides a content infrastructure for digital teams to power content in websites, apps, and devices. Unlike a CMS, Contentful was built to integrate with the modern software stack. It offers a central hub for structured content, powerful management and delivery APIs, and a customizable web app that enable developers and content creators to ship digital products faster.
Installation
------------
Install Contentful Management from the Python Package Index::
sudo pip install contentful_management
Usage
-----
Client
------
Create a client::
import contentful_management
client = contentful_management.Client('MANAGEMENT_API_TOKEN')
The api token can easily be created through the `management api documentation <https://www.contentful.com/developers/docs/references/authentication/#the-content-management-api>`_.
Spaces
------
Retrieving all spaces::
spaces = client.spaces().all()
Retrieveing one space by ID::
blog_space = client.spaces().find('blog_space_id')
Deleting a space::
client.spaces().delete('blog_space_id')
# or if you already fetched the space
blog_space.delete()
Creating a new space::
new_blog_space = client.spaces().create({'name': 'My Blog', 'default_locale': 'en-US'})
# default_locale is optional
In the case your user belongs to multiple organizations, you're required to send an organization ID::
new_blog_space = client.spaces().create({'name': 'My Blog', 'organization_id': 'my_org_id'})
Updating a space::
blog_space.update({'name': 'Ye Olde Blog'})
# or directly editing it's properties
blog_space.name = 'Ye Olde Blog'
blog_space.save()
Space Memberships
-----------------
Retrieving all memberships on a space::
memberships = client.memberships('my_space_id').all()
# or if you already have a fetched space
memberships = space.memberships().all()
Retrieveing one membership by ID::
membership = client.memberships('my_space_id').find('membership_id')
# or if you already have a fetched space
membership = space.memberships().find('membership_id')
Deleting an membership::
client.memberships('my_space_id').delete('membership_id')
# or if you already have a fetched space
space.memberships().delete('membership_id')
# or if you already have fetched the membership
memberships.delete()
Creating a new membership::
memberships = client.memberships('my_space_id').create({
"admin": False,
"roles": [
{
"type": "Link",
"linkType": "Role",
"id": "1Nq88dKTNXNaxkbrRpEEw6"
}
],
"email": "test@example.com"
})
# or if you already have a fetched space
memberships = space.memberships().create({
"admin": False,
"roles": [
{
"type": "Link",
"linkType": "Role",
"id": "1Nq88dKTNXNaxkbrRpEEw6"
}
],
"email": "test@example.com"
})
Updating a membership::
memberships.update({
"admin": False,
"roles": [
{
"type": "Link",
"linkType": "Role",
"id": "1Nq88dKTNXNaxkbrRpEEw6"
}
]
})
# or directly editing it's properties
memberships.admin = True
memberships.save()
Organizations
-------------
Retrieving all Organizations you belong to::
organizations = client.organizations().all()
Usage API
---------
*Note*: This feature is available only to Commited v2 customers.
Organization Periodic Usages
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Retrieving all API Usage statistics for an Organization during a given usage period, broken down by organization for all APIs::
# Optionally, you can pass the metric, start and end date filters
usage = client.organization_periodic_usages('organization_id').all()
# For example only CDA and CMA metrics from yesterday onwards
usage = client.organization_periodic_usages('organization_id').all({'metric[in]': ['cda', 'cma'], 'startDate': (date.today() - timedelta(days=1)).isoformat()})
Alternatively, if you have an already fetched organization::
usage_periods = organization.periodic_usages().all()
Users
-----
Retrieving your User information::
user = client.users().me()
Retrieving one user by ID from the space::
user = space.users().find(user_id)
Retrieving one user by ID from an organization::
user = organization.users().find(user_id)
Environments
------------
**Note:** For all resources that depend on an environment but don't have environments explicitly enabled. You should use ``'master'`` as ``environment_id``.
Retrieving all environments on a space::
environments = client.environments('my_space_id').all()
# or if you already have a fetched space
environments = space.environments().all()
Retrieving an environment by ID::
environment = client.environments('my_space_id').find('environment_id')
# or if you already have a fetched space
environment = space.environments().find('environment_id')
Deleting an environment::
client.environments('my_space_id').delete('environment_id')
# or if you already have a fetched space
space.environments().delete('environment_id')
# or if you already fetched the environment
environment.delete()
Creating an environment::
new_environment = client.environments('my_space_id').create(
'new_environment_id',
{
'name': 'New Environment'
}
)
# or if you already have a fetched space
new_environment = space.environments().create(
'new_environment_id',
{
'name': 'New Environment'
}
)
Creating an environment with a different source::
new_environment = client.environments('my_space_id').create(
'new_environment_id',
{
'name': 'New Environment',
'source_environment_id': 'other_environment'
}
)
Assets
------
Retrieving all assets on a space::
assets = client.assets('my_space_id', 'environment_id').all()
# or if you already have a fetched environment
assets = environment.assets().all()
Retrieving an asset by ID::
asset = client.assets('my_space_id', 'environment_id').find('asset_id')
# or if you already have a fetched environment
asset = environment.assets().find('asset_id')
Deleting an asset::
client.assets('my_space_id', 'environment_id').delete('asset_id')
# or if you already have a fetched environment
environment.assets().delete('asset_id')
# or if you already fetched the asset
asset.delete()
Creating an asset::
file_attributes = {
'fields': {
'file': {
'en-US': {
'fileName': 'file.png',
'contentType': 'image/png',
'upload': 'https://url.to/file.png'
}
}
}
}
new_asset = client.assets('my_space_id', 'environment_id').create(
'new_asset_id',
file_attributes
)
# or if you already have a fetched environment
new_asset = environment.assets().create(
'new_asset_id',
file_attributes
)
We also support Direct File Upload, this will be explained in the Uploads section.
Processing an asset::
asset.process()
This will process the file for every available locale and provide you with a downloadable URL within Contentful.
Updating an asset::
asset.update(other_file_attributes)
# or directly editing it's properties
asset.file['file_name'] = 'other_file.png'
asset.save()
Deleting an asset::
client.assets('my_space_id', 'environment_id').delete('asset_id')
# or if you already have a fetched environment
environment.assets().delete('asset_id')
# or if you already fetched the asset
asset.delete()
Archiving and Unarchiving an asset::
asset.archive()
asset.unarchive()
Publishing or Unpublishing an asset::
asset.publish()
asset.unpublish()
Checking if an asset is published::
asset.is_published
Checking if an asset is updated::
asset.is_updated
Entries
-------
Retrieving all entries on a space::
entries = client.entries('my_space_id', 'environment_id').all()
# or if you already have a fetched environment
entries = environment.entries().all()
# or if you already have a fetched content type
entries_for_content_type = content_type.entries().all()
Retrieving an entry by ID::
entry = client.entries('my_space_id', 'environment_id').find('entry_id')
# or if you already have a fetched environment
entry = environment.entries().find('entry_id')
# or if you already have a fetched content type
entry = content_type.entries().find('entry_id')
Deleting an entry::
client.entries('my_space_id', 'environment_id').delete('entry_id')
# or if you already have a fetched environment
environment.entries().delete('entry_id')
# or if you already fetched the entry
entry.delete()
Creating an entry::
entry_attributes = {
'content_type_id': 'target_content_type',
'fields': {
'title': {
'en-US': 'My Awesome Post'
},
'body': {
'en-US': 'Once upon a time...'
}
}
}
new_entry = client.entries('my_space_id', 'environment_id').create(
'new_entry_id',
entry_attributes
)
# or if you already have a fetched environment
new_entry = environment.entries().create(
'new_entry_id',
entry_attributes
)
Updating an entry::
entry.update(other_entry_attributes)
# or directly updating it's properties
entry.title = 'My Super Post'
entry.save()
Updating an entry for multiple locales::
for target_locale in ['en-US', 'es-AR']:
entry.sys['locale'] = target_locale
entry.title = 'Post in {0}'.format(target_locale)
entry.save()
entry.fields('en-US')['title'] # will return "Post in en-US"
entry.fields('es-AR')['title'] # will return "Post in es-AR"
Accessing localized fields::
entry.sys['locale'] = 'es-AR'
entry.title # will now be equivalent to entry.fields('es-AR')['title']
Deleting an entry::
client.entries('my_space_id', 'environment_id').delete('entry_id')
# or if you already have a fetched environment
environment.entries().delete('entry_id')
# or if you already fetched the entry
entry.delete()
Archiving and Unarchiving an entry::
entry.archive()
entry.unarchive()
Publishing or Unpublishing an entry::
entry.publish()
entry.unpublish()
Checking if an entry is published::
entry.is_published
Checking if an entry is updated::
entry.is_updated
**Note**:
Entries created with *empty fields*, will not return those fields in the response.
Therefore, if you want to explicitly set those fields to empty (``None``) you will need to make an extra request to fetch the Content Type and fill the missing fields.
Tags
----
Retrieving all tags on a space::
tags = client.tags('my_space_id', 'environment_id').all()
Retrieving a tag by ID::
tag = client.tags('my_space_id', 'environment_id').find('tag_id')
Deleting a tag::
client.tags('my_space_id', 'environment_id').delete('tag_id')
Creating a tag::
new_tag = client.tags('my_space_id', 'environment_id').create('new_tag_id', {'name': 'My Tag'})
Updating a tag::
tag.update({'name': 'My New Tag'})
# or directly editing it's properties
tag.name = 'My New Tag'
tag.save()
Tagging an entry::
entry.update({"_metadata": {"tags": [{"sys": {"type": "Link", "linkType": "Tag", "id": "icon"}}]}})
Tagging an asset::
asset.update({"_metadata": {"tags": [{"sys": {"type": "Link", "linkType": "Tag", "id": "icon"}}]}})
Removing a tag from an entry::
entry.update({"_metadata": {"tags": []}})
Removing a tag from an asset::
asset.update({"_metadata": {"tags": []}})
Accessing tag of an entry or asset::
entry._metadata['tags'] or asset._metadata['tags'] # will return a list of tags
Content Types
-------------
Retrieving all content types on a space::
content_types = client.content_types('my_space_id', 'environment_id').all()
# or if you already have a fetched environment
content_types = environment.content_types().all()
Retrieving a content type by ID::
content_type = client.content_types('my_space_id', 'environment_id').find('content_type_id')
# or if you already have a fetched environment
content_type = environment.content_types().find('content_type_id')
Deleting a content type::
client.content_types('my_space_id', 'environment_id').delete('content_type_id')
# or if you already have a fetched environment
environment.content_types().delete('content_type_id')
# or if you already fetched the content type
content_type.delete()
Creating a content type::
content_type_attributes = {
'name': 'Blog Post',
'description': 'Blog Posts to be included in ...',
'fields': [
{
'disabled': False,
'id': 'title',
'localized': True,
'name': 'Title',
'omitted': False,
'required': True,
'type': 'Symbol',
'validations': [
{
'size': {'min': 3}
}
]
},
{
'disabled': False,
'id': 'body',
'localized': True,
'name': 'Body',
'omitted': False,
'required': True,
'type': 'Text',
'validations': []
}
]
}
new_content_type = client.content_types('my_space_id', 'environment_id').create(
'new_ct_id',
content_type_attributes
)
# or if you already have a fetched environment
new_content_type = environment.content_types().create(
'new_ct_id',
content_type_attributes
)
Updating a content type::
content_type.update(other_content_type_attributes)
# or directly updating it's properties
content_type.name = 'Not Post'
content_type.fields.append(
contentful_management.ContentTypeField({
'id': 'author',
'name': 'Author',
'type': 'Link',
'linkType': 'Entry'
})
)
content_type.save()
Deleting a content type::
client.content_types('my_space_id', 'environment_id').delete('content_type_id')
# or if you already have a fetched environment
environment.content_types().delete('content_type_id')
# or if you already fetched the content type
content_type.delete()
Publishing or Unpublishing a content type::
content_type.publish()
content_type.unpublish()
Checking if a content type is published::
content_type.is_published
Checking if a content type is updated::
content_type.is_updated
Removing a field from a content type::
fields = content_type.fields
# keep all fields but the one with 'author' as id
content_type.fields = [ f for f in fields if not f.id == 'author' ]
content_type.save()
Validations:
For information regarding available validations check the `reference documentation <https://www.contentful.com/developers/docs/references/content-management-api/#/reference/content-types/content-type>`_.
Locales
-------
Retrieving all locales on a space::
locales = client.locales('my_space_id', 'environment_id').all()
# or if you already have a fetched environment
locales = environment.locales().all()
Retrieveing one locale by ID::
locale = client.locales('my_space_id', 'environment_id').find('locale_id')
# or if you already have a fetched environment
locale = environment.locales().find('locale_id')
Deleting a locale::
client.locales('my_space_id', 'environment_id').delete('locale_id')
# or if you already have a fetched environment
environment.locales().delete('locale_id')
# or if you already have fetched the locale
locale.delete()
Creating a new locale::
new_locale = client.locales('my_space_id', 'environment_id').create({'name': 'Klingon', 'code': 'tlh'})
# or if you already have a fetched environment
new_locale = environment.locales().create({'name': 'Klingon', 'code': 'tlh'})
Updating a locale::
locale.update({'name': 'Elvish'})
# or directly editing it's properties
locale.name = 'Elvish'
locale.save()
Roles
-----
Retrieving all roles on a space::
roles = client.roles('my_space_id').all()
# or if you already have a fetched space
roles = space.roles().all()
Retrieveing one role by ID::
role = client.roles('my_space_id').find('role_id')
# or if you already have a fetched space
role = space.roles().find('role_id')
Deleting a role::
client.roles('my_space_id').delete('role_id')
# or if you already have a fetched space
space.roles().delete('role_id')
# or if you already have fetched the role
role.delete()
Creating a new role::
role_attributes = {
'name': 'My Role',
'description': 'foobar role',
'permissions': {
'ContentDelivery': 'all',
'ContentModel': ['read'],
'Settings': []
},
'policies': [
{
'effect': 'allow',
'actions': 'all',
'constraint': {
'and': [
{
'equals': [
{ 'doc': 'sys.type' },
'Entry'
]
},
{
'equals': [
{ 'doc': 'sys.type' },
'Asset'
]
}
]
}
}
]
}
new_role = client.roles('my_space_id').create(role_attributes)
# or if you already have a fetched space
new_role = space.roles().create(role_attributes)
Updating a role::
roles.update({'name': 'A different Role'})
# or directly editing it's properties
role.name = 'A different Role'
role.save()
Webhooks
--------
Retrieving all webhooks on a space::
webhook = client.webhooks('my_space_id').all()
# or if you already have a fetched space
webhook = space.webhooks().all()
Retrieveing one webhook by ID::
webhook = client.webhooks('my_space_id').find('webhook_id')
# or if you already have a fetched space
webhook = space.webhooks().find('webhook_id')
Deleting a webhook::
client.webhooks('my_space_id').delete('webhook_id')
# or if you already have a fetched space
space.webhooks().delete('webhook_id')
# or if you already have fetched the webhook
webhook.delete()
Creating a new webhook::
webhook_attributes = {
'name': 'My Webhook',
'url': 'https://www.example.com',
'httpBasicUsername': 'username',
'httpBasicPassword': 'password'
}
new_webhook = client.webhooks('my_space_id').create(webhook_attributes)
# or if you already have a fetched space
new_webhook = space.webhooks().create(webhook_attributes)
Updating a webhook::
webhook.update({'name': 'Other Webhook'})
# or directly editing it's properties
webhook.name = 'Other Webhook'
webhook.save()
Webhook Calls
-------------
Retrieving all Webhook Calls on a space::
calls = client.webhook_calls('my_space_id', 'webhook_id').all()
# or if you already have a fetched webhook
calls = webhook.calls().all()
Retrieveing Webhook Call Details by ID::
call = client.webhook_calls('my_space_id', 'webhook_id').find('call_id')
# or if you already have a fetched webhook
call = webhook.calls().find('call_id')
Webhook Health
--------------
Retrieving Webhook Health::
health = client.webhook_health('my_space_id', 'webhook_id').find()
# or if you already have a fetched webhook
health = webhook.health().find()
UI Extensions
-------------
Retrieving all UI Extenisons on a space::
ui_extensions = client.ui_extensions('my_space_id', 'environment_id').all()
# or if you already have a fetched environment
ui_extensions = environment.ui_extensions().all()
Retrieveing one UI Extension by ID::
ui_extension = client.ui_extensions('my_space_id', 'environment_id').find('ui_extension_id')
# or if you already have a fetched environment
ui_extension = environment.ui_extensions().find('ui_extension_id')
Deleting an UI Extension::
client.ui_extensions('my_space_id', 'environment_id').delete('ui_extension_id')
# or if you already have a fetched environment
environment.ui_extensions().delete('ui_extension_id')
# or if you already have fetched the UI Extension
ui_extension.delete()
Creating a new UI Extension::
new_ui_extension = client.ui_extensions('my_space_id', 'environment_id').create('test-extension', {
"extension": {
"name": "Test Extension",
"srcdoc": "<html>foobar</html>",
"fieldTypes": [{'type': 'Symbol'}],
"sidebar": False
}
})
# or if you already have a fetched environment
new_ui_extension = environment.ui_extensions().create('test-extension', {
"extension": {
"name": "Test Extension",
"srcdoc": "<html>foobar</html>",
"fieldTypes": [{'type': 'Symbol'}],
"sidebar": False
}
})
Updating an UI Extension::
ui_extension.update({
"extension": {
"name": "Test Extension",
"srcdoc": "<html>foobar</html>",
"fieldTypes": [{'type': 'Symbol'}],
"sidebar": False
}
})
# or directly editing it's properties
ui_extension.name = 'Their API Key'
ui_extension.save()
Editor Interfaces
-----------------
Retrieving the editor interfaces for a content type::
editor_interface = client.editor_interfaces('my_space_id', 'environment_id', 'my_content_type_id').find()
# or if you already have a fetched content type
editor_interface = content_type.editor_interfaces().find()
Updating the editor interface::
controls = [
{
'widgetId': 'singleLine',
'fieldId': 'name',
'settings': {}
}
]
editor_interface.update({'controls': controls})
# or directly editing it's properties
editor_interface.controls = controls
editor_interface.save()
Entry Snapshots
---------------
Retrieving all snapshots for an entry::
snapshots = client.snapshots('my_space_id', 'environment_id', 'entry_id').all()
# or if you already have a fetched entry
snapshots = entry.snapshots().all()
Retrieveing one snapshot by ID::
snapshot = client.snapshots('my_space_id', 'environment_id', 'entry_id').find('snapshot_id')
# or if you already have a fetched entry
snapshot = entry.snapshots().find('snapshot_id')
Content Type Snapshots
----------------------
Retrieving all snapshots for a content type::
snapshots = client.content_type_snapshots('my_space_id', 'environment_id', 'content_type_id').all()
# or if you already have a fetched content type
snapshots = content_type.snapshots().all()
Retrieveing one snapshot by ID::
snapshot = client.content_type_snapshots('my_space_id', 'environment_id', 'content_type_id').find('snapshot_id')
# or if you already have a fetched content_type
snapshot = content_type.snapshots().find('snapshot_id')
API Keys
--------
Retrieving all API keys on a space::
api_keys = client.api_keys('my_space_id').all()
# or if you already have a fetched space
api_keys = space.api_keys().all()
Retrieveing one API key by ID::
api_key = client.api_keys('my_space_id').find('api_key_id')
# or if you already have a fetched space
api_key = space.api_keys().find('api_key_id')
Deleting an API key::
client.api_keys('my_space_id').delete('api_key_id')
# or if you already have a fetched space
space.api_keys().delete('api_key_id')
# or if you already have fetched the API key
api_key.delete()
Creating a new API key::
new_api_key = client.api_keys('my_space_id').create({'name': 'My API Key'})
# or if you already have a fetched space
new_api_key = space.api_keys().create({'name': 'My API Key'})
Creating a new API key with multiple environments::
environments = [
{
"sys": {
"type": "Link",
"linkType": "Environment",
"id": "master"
}
},
{
"sys": {
"type": "Link",
"linkType": "Environment",
"id": "staging"
}
}
]
new_api_key = client.api_keys('my_space_id').create({'name': 'My API Key with environments', 'environments': environments})
# or if you already have a fetched space
new_api_key = space.api_keys().create({'name': 'My API Key with environments', 'environments': environments})
Updating an API key::
api_key.update({'name': 'Their API Key'})
# or directly editing it's properties
api_key.name = 'Their API Key'
api_key.save()
Updating an API key with a new environment, while retaining the existing ones::
new_environment_link = Link({
"sys": {
"type": "Link",
"linkType": "Environment",
"id": "staging"
}
})
api_key.environments.append(new_environment_link)
api_key.save()
Preview API Keys
----------------
Retrieving all Preview API keys on a space::
preview_api_keys = client.preview_api_keys('my_space_id').all()
# or if you already have a fetched space
preview_api_keys = space.preview_api_keys().all()
Retrieveing one API key by ID::
preview_api_key = client.preview_api_keys('my_space_id').find('preview_api_key_id')
# or if you already have a fetched space
preview_api_key = space.preview_api_keys().find('preview_api_key_id')
# or if you have an already fetched api key
preview_api_key = api_key.preview_api_key()
Personal Access Tokens
----------------------
Retrieving all Personal Access Tokens on a space::
personal_access_tokens = client.personal_access_tokens().all()
Retrieveing one Personal Access Token by ID::
personal_access_token = client.personal_access_tokens().find('personal_access_token_id')
Revoking a Personal Access Token::
client.personal_access_tokens().revoke('personal_access_token_id')
# or if you already have fetched the Personal Access Token
personal_access_tokens.delete()
Creating a new Personal Access Token::
new_personal_access_token = client.personal_access_tokens().create({
'name': 'My API Key',
'scopes': ['content_management_manage']
})
Uploads
-------
Retrieveing one upload by ID::
upload = client.uploads('my_space_id').find('upload_id')
# or if you already have a fetched space
upload = space.uploads().find('upload_id')
Deleting a upload::
client.uploads('my_space_id').delete('upload_id')
# or if you already have a fetched space
space.uploads().delete('upload_id')
# or if you already have fetched the upload
upload.delete()
Creating a new upload::
# you can use either a file-like object or a path.
# If you use a path, the SDK will open it, create the upload and
# close the file afterwards.
with open('path/to/my/file.txt', 'rb') as file:
new_upload = client.uploads('my_space_id').create(file)
# or if you already have a fetched space
new_upload = space.uploads().create('path/to/file.txt')
Associating an upload with a new asset::
# notice that the upload is converted to a link,
# and the JSON representation is then sent.
client.assets('my_space_id', 'environment_id').create(
'new_asset_id',
{
'fields': {
'file': {
'en-US': {
'fileName': 'some_name.png',
'contentType': 'image/png',
'uploadFrom': upload.to_link().to_json()
}
}
}
}
)
Client Configuration Options
----------------------------
``access_token``: API Access Token.
``api_url``: (optional) URL of the Contentful Target API, defaults to Management API.
``uploads_api_url``: (optional) URL of the Contentful Upload Target API, defaults to Upload API.
``api_version``: (optional) Target version of the Contentful API.
``default_locale``: (optional) Default Locale for your Spaces, defaults to 'en-US'.
``https``: (optional) Boolean determining wether to use https or http, defaults to True.
``authorization_as_header``: (optional) Boolean determining wether to send access_token through a header or via GET params, defaults to True.
``raw_mode``: (optional) Boolean determining wether to process the response or return it raw after each API call, defaults to True.
``gzip_encoded``: (optional) Boolean determining wether to accept gzip encoded results, defaults to True.
``raise_errors``: (optional) Boolean determining wether to raise an exception on requests that aren't successful, defaults to True.
``content_type_cache``: (optional) Boolean determining wether to store a Cache of the Content Types in order to properly coerce Entry fields, defaults to True.
``proxy_host``: (optional) URL for Proxy, defaults to None.
``proxy_port``: (optional) Port for Proxy, defaults to None.
``proxy_username``: (optional) Username for Proxy, defaults to None.
``proxy_password``: (optional) Password for Proxy, defaults to None.
``max_rate_limit_retries``: (optional) Maximum amount of retries after RateLimitError, defaults to 1.
``max_rate_limit_wait``: (optional) Timeout (in seconds) for waiting for retry after RateLimitError, defaults to 60.
``application_name``: (optional) User application name, defaults to None.
``application_version``: (optional) User application version, defaults to None.
``integration_name``: (optional) Integration name, defaults to None.
``integration_version``: (optional) Integration version, defaults to None.
Logging
-------
To use the logger, use the standard library ``logging`` module::
import logging
logging.basicConfig(level=logging.DEBUG)
client.entries().all()
# INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): api.contentful.com
# DEBUG:requests.packages.urllib3.connectionpool:"GET /spaces/cfexampleapi/entries HTTP/1.1" 200 1994
License
-------
Copyright (c) 2017 Contentful GmbH. See LICENSE for details.
Contributing
------------
Feel free to improve this tool by submitting a Pull Request.
Raw data
{
"_id": null,
"home_page": null,
"name": "contentful_management",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "contentful, management, cma, cms, content",
"author": null,
"author_email": "Contentful GmbH <prd-ecosystem-dx@contentful.com>",
"download_url": "https://files.pythonhosted.org/packages/e2/cb/467cd26668e870735f77e87b5d2c6efe3000ec33d8156304043031e09a8f/contentful_management-2.14.4.tar.gz",
"platform": null,
"description": "Contentful Management API SDK\n=============================\n\n.. image:: https://travis-ci.org/contentful/contentful-management.py.svg?branch=master\n :target: https://travis-ci.org/contentful/contentful-management.py\n\n`Contentful <https://www.contentful.com>`_ provides a content infrastructure for digital teams to power content in websites, apps, and devices. Unlike a CMS, Contentful was built to integrate with the modern software stack. It offers a central hub for structured content, powerful management and delivery APIs, and a customizable web app that enable developers and content creators to ship digital products faster.\n\nInstallation\n------------\n\nInstall Contentful Management from the Python Package Index::\n\n sudo pip install contentful_management\n\nUsage\n-----\n\nClient\n------\n\nCreate a client::\n\n import contentful_management\n\n client = contentful_management.Client('MANAGEMENT_API_TOKEN')\n\nThe api token can easily be created through the `management api documentation <https://www.contentful.com/developers/docs/references/authentication/#the-content-management-api>`_.\n\nSpaces\n------\n\nRetrieving all spaces::\n\n spaces = client.spaces().all()\n\nRetrieveing one space by ID::\n\n blog_space = client.spaces().find('blog_space_id')\n\nDeleting a space::\n\n client.spaces().delete('blog_space_id')\n\n # or if you already fetched the space\n\n blog_space.delete()\n\nCreating a new space::\n\n new_blog_space = client.spaces().create({'name': 'My Blog', 'default_locale': 'en-US'})\n # default_locale is optional\n\nIn the case your user belongs to multiple organizations, you're required to send an organization ID::\n\n new_blog_space = client.spaces().create({'name': 'My Blog', 'organization_id': 'my_org_id'})\n\nUpdating a space::\n\n blog_space.update({'name': 'Ye Olde Blog'})\n\n # or directly editing it's properties\n\n blog_space.name = 'Ye Olde Blog'\n blog_space.save()\n\nSpace Memberships\n-----------------\n\nRetrieving all memberships on a space::\n\n memberships = client.memberships('my_space_id').all()\n\n # or if you already have a fetched space\n\n memberships = space.memberships().all()\n\nRetrieveing one membership by ID::\n\n membership = client.memberships('my_space_id').find('membership_id')\n\n # or if you already have a fetched space\n\n membership = space.memberships().find('membership_id')\n\nDeleting an membership::\n\n client.memberships('my_space_id').delete('membership_id')\n\n # or if you already have a fetched space\n\n space.memberships().delete('membership_id')\n\n # or if you already have fetched the membership\n\n memberships.delete()\n\nCreating a new membership::\n\n memberships = client.memberships('my_space_id').create({\n \"admin\": False,\n \"roles\": [\n {\n \"type\": \"Link\",\n \"linkType\": \"Role\",\n \"id\": \"1Nq88dKTNXNaxkbrRpEEw6\"\n }\n ],\n \"email\": \"test@example.com\"\n })\n\n\n # or if you already have a fetched space\n\n memberships = space.memberships().create({\n \"admin\": False,\n \"roles\": [\n {\n \"type\": \"Link\",\n \"linkType\": \"Role\",\n \"id\": \"1Nq88dKTNXNaxkbrRpEEw6\"\n }\n ],\n \"email\": \"test@example.com\"\n })\n\nUpdating a membership::\n\n memberships.update({\n \"admin\": False,\n \"roles\": [\n {\n \"type\": \"Link\",\n \"linkType\": \"Role\",\n \"id\": \"1Nq88dKTNXNaxkbrRpEEw6\"\n }\n ]\n })\n\n\n # or directly editing it's properties\n\n memberships.admin = True\n memberships.save()\n\nOrganizations\n-------------\n\nRetrieving all Organizations you belong to::\n\n organizations = client.organizations().all()\n\nUsage API\n---------\n\n*Note*: This feature is available only to Commited v2 customers.\n\nOrganization Periodic Usages\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nRetrieving all API Usage statistics for an Organization during a given usage period, broken down by organization for all APIs::\n\n # Optionally, you can pass the metric, start and end date filters\n usage = client.organization_periodic_usages('organization_id').all()\n # For example only CDA and CMA metrics from yesterday onwards\n usage = client.organization_periodic_usages('organization_id').all({'metric[in]': ['cda', 'cma'], 'startDate': (date.today() - timedelta(days=1)).isoformat()})\n\nAlternatively, if you have an already fetched organization::\n\n usage_periods = organization.periodic_usages().all()\n\nUsers\n-----\n\nRetrieving your User information::\n\n user = client.users().me()\n\nRetrieving one user by ID from the space::\n\n user = space.users().find(user_id)\n\nRetrieving one user by ID from an organization::\n\n user = organization.users().find(user_id)\n\nEnvironments\n------------\n\n**Note:** For all resources that depend on an environment but don't have environments explicitly enabled. You should use ``'master'`` as ``environment_id``.\n\nRetrieving all environments on a space::\n\n environments = client.environments('my_space_id').all()\n\n # or if you already have a fetched space\n\n environments = space.environments().all()\n\nRetrieving an environment by ID::\n\n environment = client.environments('my_space_id').find('environment_id')\n\n # or if you already have a fetched space\n\n environment = space.environments().find('environment_id')\n\nDeleting an environment::\n\n client.environments('my_space_id').delete('environment_id')\n\n # or if you already have a fetched space\n\n space.environments().delete('environment_id')\n\n # or if you already fetched the environment\n\n environment.delete()\n\nCreating an environment::\n\n new_environment = client.environments('my_space_id').create(\n 'new_environment_id',\n {\n 'name': 'New Environment'\n }\n )\n\n # or if you already have a fetched space\n\n new_environment = space.environments().create(\n 'new_environment_id',\n {\n 'name': 'New Environment'\n }\n )\n\nCreating an environment with a different source::\n\n new_environment = client.environments('my_space_id').create(\n 'new_environment_id',\n {\n 'name': 'New Environment',\n 'source_environment_id': 'other_environment'\n }\n )\n\nAssets\n------\n\nRetrieving all assets on a space::\n\n assets = client.assets('my_space_id', 'environment_id').all()\n\n # or if you already have a fetched environment\n\n assets = environment.assets().all()\n\nRetrieving an asset by ID::\n\n asset = client.assets('my_space_id', 'environment_id').find('asset_id')\n\n # or if you already have a fetched environment\n\n asset = environment.assets().find('asset_id')\n\nDeleting an asset::\n\n client.assets('my_space_id', 'environment_id').delete('asset_id')\n\n # or if you already have a fetched environment\n\n environment.assets().delete('asset_id')\n\n # or if you already fetched the asset\n\n asset.delete()\n\nCreating an asset::\n\n file_attributes = {\n 'fields': {\n 'file': {\n 'en-US': {\n 'fileName': 'file.png',\n 'contentType': 'image/png',\n 'upload': 'https://url.to/file.png'\n }\n }\n }\n }\n\n new_asset = client.assets('my_space_id', 'environment_id').create(\n 'new_asset_id',\n file_attributes\n )\n\n # or if you already have a fetched environment\n\n new_asset = environment.assets().create(\n 'new_asset_id',\n file_attributes\n )\n\nWe also support Direct File Upload, this will be explained in the Uploads section.\n\nProcessing an asset::\n\n asset.process()\n\nThis will process the file for every available locale and provide you with a downloadable URL within Contentful.\n\nUpdating an asset::\n\n asset.update(other_file_attributes)\n\n # or directly editing it's properties\n\n asset.file['file_name'] = 'other_file.png'\n asset.save()\n\nDeleting an asset::\n\n client.assets('my_space_id', 'environment_id').delete('asset_id')\n\n # or if you already have a fetched environment\n\n environment.assets().delete('asset_id')\n\n # or if you already fetched the asset\n\n asset.delete()\n\nArchiving and Unarchiving an asset::\n\n asset.archive()\n asset.unarchive()\n\nPublishing or Unpublishing an asset::\n\n asset.publish()\n asset.unpublish()\n\nChecking if an asset is published::\n\n asset.is_published\n\nChecking if an asset is updated::\n\n asset.is_updated\n\nEntries\n-------\n\nRetrieving all entries on a space::\n\n entries = client.entries('my_space_id', 'environment_id').all()\n\n # or if you already have a fetched environment\n\n entries = environment.entries().all()\n\n # or if you already have a fetched content type\n\n entries_for_content_type = content_type.entries().all()\n\nRetrieving an entry by ID::\n\n entry = client.entries('my_space_id', 'environment_id').find('entry_id')\n\n # or if you already have a fetched environment\n\n entry = environment.entries().find('entry_id')\n\n # or if you already have a fetched content type\n\n entry = content_type.entries().find('entry_id')\n\nDeleting an entry::\n\n client.entries('my_space_id', 'environment_id').delete('entry_id')\n\n # or if you already have a fetched environment\n\n environment.entries().delete('entry_id')\n\n # or if you already fetched the entry\n\n entry.delete()\n\nCreating an entry::\n\n entry_attributes = {\n 'content_type_id': 'target_content_type',\n 'fields': {\n 'title': {\n 'en-US': 'My Awesome Post'\n },\n 'body': {\n 'en-US': 'Once upon a time...'\n }\n }\n }\n\n new_entry = client.entries('my_space_id', 'environment_id').create(\n 'new_entry_id',\n entry_attributes\n )\n\n # or if you already have a fetched environment\n\n new_entry = environment.entries().create(\n 'new_entry_id',\n entry_attributes\n )\n\nUpdating an entry::\n\n entry.update(other_entry_attributes)\n\n # or directly updating it's properties\n\n entry.title = 'My Super Post'\n entry.save()\n\nUpdating an entry for multiple locales::\n\n for target_locale in ['en-US', 'es-AR']:\n entry.sys['locale'] = target_locale\n entry.title = 'Post in {0}'.format(target_locale)\n entry.save()\n\n entry.fields('en-US')['title'] # will return \"Post in en-US\"\n entry.fields('es-AR')['title'] # will return \"Post in es-AR\"\n\nAccessing localized fields::\n\n entry.sys['locale'] = 'es-AR'\n entry.title # will now be equivalent to entry.fields('es-AR')['title']\n\nDeleting an entry::\n\n client.entries('my_space_id', 'environment_id').delete('entry_id')\n\n # or if you already have a fetched environment\n\n environment.entries().delete('entry_id')\n\n # or if you already fetched the entry\n\n entry.delete()\n\nArchiving and Unarchiving an entry::\n\n entry.archive()\n entry.unarchive()\n\nPublishing or Unpublishing an entry::\n\n entry.publish()\n entry.unpublish()\n\nChecking if an entry is published::\n\n entry.is_published\n\nChecking if an entry is updated::\n\n entry.is_updated\n\n\n**Note**:\n\n Entries created with *empty fields*, will not return those fields in the response.\n Therefore, if you want to explicitly set those fields to empty (``None``) you will need to make an extra request to fetch the Content Type and fill the missing fields.\n\nTags\n----\n\nRetrieving all tags on a space::\n\n tags = client.tags('my_space_id', 'environment_id').all()\n\nRetrieving a tag by ID::\n\n tag = client.tags('my_space_id', 'environment_id').find('tag_id')\n\n\nDeleting a tag::\n\n client.tags('my_space_id', 'environment_id').delete('tag_id')\n\nCreating a tag::\n\n new_tag = client.tags('my_space_id', 'environment_id').create('new_tag_id', {'name': 'My Tag'})\n\nUpdating a tag::\n\n tag.update({'name': 'My New Tag'})\n\n # or directly editing it's properties\n\n tag.name = 'My New Tag'\n tag.save()\n\nTagging an entry::\n\n entry.update({\"_metadata\": {\"tags\": [{\"sys\": {\"type\": \"Link\", \"linkType\": \"Tag\", \"id\": \"icon\"}}]}})\n\nTagging an asset::\n\n asset.update({\"_metadata\": {\"tags\": [{\"sys\": {\"type\": \"Link\", \"linkType\": \"Tag\", \"id\": \"icon\"}}]}})\n\nRemoving a tag from an entry::\n\n entry.update({\"_metadata\": {\"tags\": []}})\n\nRemoving a tag from an asset::\n\n asset.update({\"_metadata\": {\"tags\": []}})\n\nAccessing tag of an entry or asset::\n\n entry._metadata['tags'] or asset._metadata['tags'] # will return a list of tags\n\nContent Types\n-------------\n\nRetrieving all content types on a space::\n\n content_types = client.content_types('my_space_id', 'environment_id').all()\n\n # or if you already have a fetched environment\n\n content_types = environment.content_types().all()\n\nRetrieving a content type by ID::\n\n content_type = client.content_types('my_space_id', 'environment_id').find('content_type_id')\n\n # or if you already have a fetched environment\n\n content_type = environment.content_types().find('content_type_id')\n\nDeleting a content type::\n\n client.content_types('my_space_id', 'environment_id').delete('content_type_id')\n\n # or if you already have a fetched environment\n\n environment.content_types().delete('content_type_id')\n\n # or if you already fetched the content type\n\n content_type.delete()\n\nCreating a content type::\n\n content_type_attributes = {\n 'name': 'Blog Post',\n 'description': 'Blog Posts to be included in ...',\n 'fields': [\n {\n 'disabled': False,\n 'id': 'title',\n 'localized': True,\n 'name': 'Title',\n 'omitted': False,\n 'required': True,\n 'type': 'Symbol',\n 'validations': [\n {\n 'size': {'min': 3}\n }\n ]\n },\n {\n 'disabled': False,\n 'id': 'body',\n 'localized': True,\n 'name': 'Body',\n 'omitted': False,\n 'required': True,\n 'type': 'Text',\n 'validations': []\n }\n ]\n }\n\n new_content_type = client.content_types('my_space_id', 'environment_id').create(\n 'new_ct_id',\n content_type_attributes\n )\n\n # or if you already have a fetched environment\n\n new_content_type = environment.content_types().create(\n 'new_ct_id',\n content_type_attributes\n )\n\nUpdating a content type::\n\n content_type.update(other_content_type_attributes)\n\n # or directly updating it's properties\n\n content_type.name = 'Not Post'\n content_type.fields.append(\n contentful_management.ContentTypeField({\n 'id': 'author',\n 'name': 'Author',\n 'type': 'Link',\n 'linkType': 'Entry'\n })\n )\n content_type.save()\n\nDeleting a content type::\n\n client.content_types('my_space_id', 'environment_id').delete('content_type_id')\n\n # or if you already have a fetched environment\n\n environment.content_types().delete('content_type_id')\n\n # or if you already fetched the content type\n\n content_type.delete()\n\nPublishing or Unpublishing a content type::\n\n content_type.publish()\n content_type.unpublish()\n\nChecking if a content type is published::\n\n content_type.is_published\n\nChecking if a content type is updated::\n\n content_type.is_updated\n\nRemoving a field from a content type::\n\n fields = content_type.fields\n\n # keep all fields but the one with 'author' as id\n\n content_type.fields = [ f for f in fields if not f.id == 'author' ]\n content_type.save()\n\nValidations:\n\n For information regarding available validations check the `reference documentation <https://www.contentful.com/developers/docs/references/content-management-api/#/reference/content-types/content-type>`_.\n\nLocales\n-------\n\nRetrieving all locales on a space::\n\n locales = client.locales('my_space_id', 'environment_id').all()\n\n # or if you already have a fetched environment\n\n locales = environment.locales().all()\n\nRetrieveing one locale by ID::\n\n locale = client.locales('my_space_id', 'environment_id').find('locale_id')\n\n # or if you already have a fetched environment\n\n locale = environment.locales().find('locale_id')\n\nDeleting a locale::\n\n client.locales('my_space_id', 'environment_id').delete('locale_id')\n\n # or if you already have a fetched environment\n\n environment.locales().delete('locale_id')\n\n # or if you already have fetched the locale\n\n locale.delete()\n\nCreating a new locale::\n\n new_locale = client.locales('my_space_id', 'environment_id').create({'name': 'Klingon', 'code': 'tlh'})\n\n # or if you already have a fetched environment\n\n new_locale = environment.locales().create({'name': 'Klingon', 'code': 'tlh'})\n\nUpdating a locale::\n\n locale.update({'name': 'Elvish'})\n\n # or directly editing it's properties\n\n locale.name = 'Elvish'\n locale.save()\n\nRoles\n-----\n\nRetrieving all roles on a space::\n\n roles = client.roles('my_space_id').all()\n\n # or if you already have a fetched space\n\n roles = space.roles().all()\n\nRetrieveing one role by ID::\n\n role = client.roles('my_space_id').find('role_id')\n\n # or if you already have a fetched space\n\n role = space.roles().find('role_id')\n\nDeleting a role::\n\n client.roles('my_space_id').delete('role_id')\n\n # or if you already have a fetched space\n\n space.roles().delete('role_id')\n\n # or if you already have fetched the role\n\n role.delete()\n\nCreating a new role::\n\n role_attributes = {\n 'name': 'My Role',\n 'description': 'foobar role',\n 'permissions': {\n 'ContentDelivery': 'all',\n 'ContentModel': ['read'],\n 'Settings': []\n },\n 'policies': [\n {\n 'effect': 'allow',\n 'actions': 'all',\n 'constraint': {\n 'and': [\n {\n 'equals': [\n { 'doc': 'sys.type' },\n 'Entry'\n ]\n },\n {\n 'equals': [\n { 'doc': 'sys.type' },\n 'Asset'\n ]\n }\n ]\n }\n }\n ]\n }\n\n new_role = client.roles('my_space_id').create(role_attributes)\n\n # or if you already have a fetched space\n\n new_role = space.roles().create(role_attributes)\n\nUpdating a role::\n\n roles.update({'name': 'A different Role'})\n\n # or directly editing it's properties\n\n role.name = 'A different Role'\n role.save()\n\nWebhooks\n--------\n\nRetrieving all webhooks on a space::\n\n webhook = client.webhooks('my_space_id').all()\n\n # or if you already have a fetched space\n\n webhook = space.webhooks().all()\n\nRetrieveing one webhook by ID::\n\n webhook = client.webhooks('my_space_id').find('webhook_id')\n\n # or if you already have a fetched space\n\n webhook = space.webhooks().find('webhook_id')\n\nDeleting a webhook::\n\n client.webhooks('my_space_id').delete('webhook_id')\n\n # or if you already have a fetched space\n\n space.webhooks().delete('webhook_id')\n\n # or if you already have fetched the webhook\n\n webhook.delete()\n\nCreating a new webhook::\n\n webhook_attributes = {\n 'name': 'My Webhook',\n 'url': 'https://www.example.com',\n 'httpBasicUsername': 'username',\n 'httpBasicPassword': 'password'\n }\n\n new_webhook = client.webhooks('my_space_id').create(webhook_attributes)\n\n # or if you already have a fetched space\n\n new_webhook = space.webhooks().create(webhook_attributes)\n\nUpdating a webhook::\n\n webhook.update({'name': 'Other Webhook'})\n\n # or directly editing it's properties\n\n webhook.name = 'Other Webhook'\n webhook.save()\n\nWebhook Calls\n-------------\n\nRetrieving all Webhook Calls on a space::\n\n calls = client.webhook_calls('my_space_id', 'webhook_id').all()\n\n # or if you already have a fetched webhook\n\n calls = webhook.calls().all()\n\nRetrieveing Webhook Call Details by ID::\n\n call = client.webhook_calls('my_space_id', 'webhook_id').find('call_id')\n\n # or if you already have a fetched webhook\n\n call = webhook.calls().find('call_id')\n\nWebhook Health\n--------------\n\nRetrieving Webhook Health::\n\n health = client.webhook_health('my_space_id', 'webhook_id').find()\n\n # or if you already have a fetched webhook\n\n health = webhook.health().find()\n\nUI Extensions\n-------------\n\nRetrieving all UI Extenisons on a space::\n\n ui_extensions = client.ui_extensions('my_space_id', 'environment_id').all()\n\n # or if you already have a fetched environment\n\n ui_extensions = environment.ui_extensions().all()\n\nRetrieveing one UI Extension by ID::\n\n ui_extension = client.ui_extensions('my_space_id', 'environment_id').find('ui_extension_id')\n\n # or if you already have a fetched environment\n\n ui_extension = environment.ui_extensions().find('ui_extension_id')\n\nDeleting an UI Extension::\n\n client.ui_extensions('my_space_id', 'environment_id').delete('ui_extension_id')\n\n # or if you already have a fetched environment\n\n environment.ui_extensions().delete('ui_extension_id')\n\n # or if you already have fetched the UI Extension\n\n ui_extension.delete()\n\nCreating a new UI Extension::\n\n new_ui_extension = client.ui_extensions('my_space_id', 'environment_id').create('test-extension', {\n \"extension\": {\n \"name\": \"Test Extension\",\n \"srcdoc\": \"<html>foobar</html>\",\n \"fieldTypes\": [{'type': 'Symbol'}],\n \"sidebar\": False\n }\n })\n\n # or if you already have a fetched environment\n\n new_ui_extension = environment.ui_extensions().create('test-extension', {\n \"extension\": {\n \"name\": \"Test Extension\",\n \"srcdoc\": \"<html>foobar</html>\",\n \"fieldTypes\": [{'type': 'Symbol'}],\n \"sidebar\": False\n }\n })\n\nUpdating an UI Extension::\n\n ui_extension.update({\n \"extension\": {\n \"name\": \"Test Extension\",\n \"srcdoc\": \"<html>foobar</html>\",\n \"fieldTypes\": [{'type': 'Symbol'}],\n \"sidebar\": False\n }\n })\n\n # or directly editing it's properties\n\n ui_extension.name = 'Their API Key'\n ui_extension.save()\n\nEditor Interfaces\n-----------------\n\nRetrieving the editor interfaces for a content type::\n\n editor_interface = client.editor_interfaces('my_space_id', 'environment_id', 'my_content_type_id').find()\n\n # or if you already have a fetched content type\n\n editor_interface = content_type.editor_interfaces().find()\n\nUpdating the editor interface::\n\n controls = [\n {\n 'widgetId': 'singleLine',\n 'fieldId': 'name',\n 'settings': {}\n }\n ]\n\n editor_interface.update({'controls': controls})\n\n # or directly editing it's properties\n\n editor_interface.controls = controls\n editor_interface.save()\n\nEntry Snapshots\n---------------\n\nRetrieving all snapshots for an entry::\n\n snapshots = client.snapshots('my_space_id', 'environment_id', 'entry_id').all()\n\n # or if you already have a fetched entry\n\n snapshots = entry.snapshots().all()\n\nRetrieveing one snapshot by ID::\n\n snapshot = client.snapshots('my_space_id', 'environment_id', 'entry_id').find('snapshot_id')\n\n # or if you already have a fetched entry\n\n snapshot = entry.snapshots().find('snapshot_id')\n\nContent Type Snapshots\n----------------------\n\nRetrieving all snapshots for a content type::\n\n snapshots = client.content_type_snapshots('my_space_id', 'environment_id', 'content_type_id').all()\n\n # or if you already have a fetched content type\n\n snapshots = content_type.snapshots().all()\n\nRetrieveing one snapshot by ID::\n\n snapshot = client.content_type_snapshots('my_space_id', 'environment_id', 'content_type_id').find('snapshot_id')\n\n # or if you already have a fetched content_type\n\n snapshot = content_type.snapshots().find('snapshot_id')\n\nAPI Keys\n--------\n\nRetrieving all API keys on a space::\n\n api_keys = client.api_keys('my_space_id').all()\n\n # or if you already have a fetched space\n\n api_keys = space.api_keys().all()\n\nRetrieveing one API key by ID::\n\n api_key = client.api_keys('my_space_id').find('api_key_id')\n\n # or if you already have a fetched space\n\n api_key = space.api_keys().find('api_key_id')\n\nDeleting an API key::\n\n client.api_keys('my_space_id').delete('api_key_id')\n\n # or if you already have a fetched space\n\n space.api_keys().delete('api_key_id')\n\n # or if you already have fetched the API key\n\n api_key.delete()\n\nCreating a new API key::\n\n new_api_key = client.api_keys('my_space_id').create({'name': 'My API Key'})\n\n # or if you already have a fetched space\n\n new_api_key = space.api_keys().create({'name': 'My API Key'})\n\nCreating a new API key with multiple environments::\n\n environments = [\n {\n \"sys\": {\n \"type\": \"Link\",\n \"linkType\": \"Environment\",\n \"id\": \"master\"\n }\n },\n {\n \"sys\": {\n \"type\": \"Link\",\n \"linkType\": \"Environment\",\n \"id\": \"staging\"\n }\n }\n ]\n\n new_api_key = client.api_keys('my_space_id').create({'name': 'My API Key with environments', 'environments': environments})\n\n # or if you already have a fetched space\n\n new_api_key = space.api_keys().create({'name': 'My API Key with environments', 'environments': environments})\n\nUpdating an API key::\n\n api_key.update({'name': 'Their API Key'})\n\n # or directly editing it's properties\n\n api_key.name = 'Their API Key'\n api_key.save()\n\nUpdating an API key with a new environment, while retaining the existing ones::\n\n new_environment_link = Link({\n \"sys\": {\n \"type\": \"Link\",\n \"linkType\": \"Environment\",\n \"id\": \"staging\"\n }\n })\n api_key.environments.append(new_environment_link)\n api_key.save()\n\nPreview API Keys\n----------------\n\nRetrieving all Preview API keys on a space::\n\n preview_api_keys = client.preview_api_keys('my_space_id').all()\n\n # or if you already have a fetched space\n\n preview_api_keys = space.preview_api_keys().all()\n\nRetrieveing one API key by ID::\n\n preview_api_key = client.preview_api_keys('my_space_id').find('preview_api_key_id')\n\n # or if you already have a fetched space\n\n preview_api_key = space.preview_api_keys().find('preview_api_key_id')\n\n # or if you have an already fetched api key\n\n preview_api_key = api_key.preview_api_key()\n\nPersonal Access Tokens\n----------------------\n\nRetrieving all Personal Access Tokens on a space::\n\n personal_access_tokens = client.personal_access_tokens().all()\n\nRetrieveing one Personal Access Token by ID::\n\n personal_access_token = client.personal_access_tokens().find('personal_access_token_id')\n\nRevoking a Personal Access Token::\n\n client.personal_access_tokens().revoke('personal_access_token_id')\n\n # or if you already have fetched the Personal Access Token\n\n personal_access_tokens.delete()\n\nCreating a new Personal Access Token::\n\n new_personal_access_token = client.personal_access_tokens().create({\n 'name': 'My API Key',\n 'scopes': ['content_management_manage']\n })\n\nUploads\n-------\n\nRetrieveing one upload by ID::\n\n upload = client.uploads('my_space_id').find('upload_id')\n\n # or if you already have a fetched space\n\n upload = space.uploads().find('upload_id')\n\nDeleting a upload::\n\n client.uploads('my_space_id').delete('upload_id')\n\n # or if you already have a fetched space\n\n space.uploads().delete('upload_id')\n\n # or if you already have fetched the upload\n\n upload.delete()\n\nCreating a new upload::\n\n # you can use either a file-like object or a path.\n # If you use a path, the SDK will open it, create the upload and\n # close the file afterwards.\n\n with open('path/to/my/file.txt', 'rb') as file:\n new_upload = client.uploads('my_space_id').create(file)\n\n # or if you already have a fetched space\n\n new_upload = space.uploads().create('path/to/file.txt')\n\nAssociating an upload with a new asset::\n\n # notice that the upload is converted to a link,\n # and the JSON representation is then sent.\n\n client.assets('my_space_id', 'environment_id').create(\n 'new_asset_id',\n {\n 'fields': {\n 'file': {\n 'en-US': {\n 'fileName': 'some_name.png',\n 'contentType': 'image/png',\n 'uploadFrom': upload.to_link().to_json()\n }\n }\n }\n }\n )\n\nClient Configuration Options\n----------------------------\n\n``access_token``: API Access Token.\n\n``api_url``: (optional) URL of the Contentful Target API, defaults to Management API.\n\n``uploads_api_url``: (optional) URL of the Contentful Upload Target API, defaults to Upload API.\n\n``api_version``: (optional) Target version of the Contentful API.\n\n``default_locale``: (optional) Default Locale for your Spaces, defaults to 'en-US'.\n\n``https``: (optional) Boolean determining wether to use https or http, defaults to True.\n\n``authorization_as_header``: (optional) Boolean determining wether to send access_token through a header or via GET params, defaults to True.\n\n``raw_mode``: (optional) Boolean determining wether to process the response or return it raw after each API call, defaults to True.\n\n``gzip_encoded``: (optional) Boolean determining wether to accept gzip encoded results, defaults to True.\n\n``raise_errors``: (optional) Boolean determining wether to raise an exception on requests that aren't successful, defaults to True.\n\n``content_type_cache``: (optional) Boolean determining wether to store a Cache of the Content Types in order to properly coerce Entry fields, defaults to True.\n\n``proxy_host``: (optional) URL for Proxy, defaults to None.\n\n``proxy_port``: (optional) Port for Proxy, defaults to None.\n\n``proxy_username``: (optional) Username for Proxy, defaults to None.\n\n``proxy_password``: (optional) Password for Proxy, defaults to None.\n\n``max_rate_limit_retries``: (optional) Maximum amount of retries after RateLimitError, defaults to 1.\n\n``max_rate_limit_wait``: (optional) Timeout (in seconds) for waiting for retry after RateLimitError, defaults to 60.\n\n``application_name``: (optional) User application name, defaults to None.\n\n``application_version``: (optional) User application version, defaults to None.\n\n``integration_name``: (optional) Integration name, defaults to None.\n\n``integration_version``: (optional) Integration version, defaults to None.\n\nLogging\n-------\n\nTo use the logger, use the standard library ``logging`` module::\n\n import logging\n logging.basicConfig(level=logging.DEBUG)\n\n client.entries().all()\n # INFO:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): api.contentful.com\n # DEBUG:requests.packages.urllib3.connectionpool:\"GET /spaces/cfexampleapi/entries HTTP/1.1\" 200 1994\n\nLicense\n-------\n\nCopyright (c) 2017 Contentful GmbH. See LICENSE for details.\n\nContributing\n------------\n\nFeel free to improve this tool by submitting a Pull Request.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Contentful Management API Client",
"version": "2.14.4",
"project_urls": {
"Changelog": "https://github.com/contentful/contentful-management.py/changelog/",
"Documentation": "https://www.contentful.com/developers/docs/references/content-management-api/",
"Homepage": "https://www.contentful.com/",
"Repository": "https://github.com/contentful/contentful-management.py"
},
"split_keywords": [
"contentful",
" management",
" cma",
" cms",
" content"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e6b46d4468904cca9931766729fa1ddb0605da3d82d73a11fd5a26b48fa19e13",
"md5": "222b5e974441300b7f86e8941fe4393a",
"sha256": "4eb90dab026aaa437c0fe77d3eeeb95b251ee0d6891478c9ed4e5388150b51f0"
},
"downloads": -1,
"filename": "contentful_management-2.14.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "222b5e974441300b7f86e8941fe4393a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 80557,
"upload_time": "2024-11-08T16:49:50",
"upload_time_iso_8601": "2024-11-08T16:49:50.560368Z",
"url": "https://files.pythonhosted.org/packages/e6/b4/6d4468904cca9931766729fa1ddb0605da3d82d73a11fd5a26b48fa19e13/contentful_management-2.14.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e2cb467cd26668e870735f77e87b5d2c6efe3000ec33d8156304043031e09a8f",
"md5": "463609f5720a422af8e06b500e297f5b",
"sha256": "8ab5182b8694f9f38146e4c6018afe490319747c4ea1bca3f178373c87d5a61b"
},
"downloads": -1,
"filename": "contentful_management-2.14.4.tar.gz",
"has_sig": false,
"md5_digest": "463609f5720a422af8e06b500e297f5b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 70850,
"upload_time": "2024-11-08T16:49:51",
"upload_time_iso_8601": "2024-11-08T16:49:51.793706Z",
"url": "https://files.pythonhosted.org/packages/e2/cb/467cd26668e870735f77e87b5d2c6efe3000ec33d8156304043031e09a8f/contentful_management-2.14.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-08 16:49:51",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "contentful",
"github_project": "contentful-management.py",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"circle": true,
"tox": true,
"lcname": "contentful_management"
}