SDKs overview
Contentful offers a suite of Software Development Kits (SDKs) designed to streamline interaction with its Content Delivery API (CDA) and Content Management API (CMA). These SDKs abstract the complexities of HTTP requests, authentication, and response parsing, allowing developers to focus on application logic. The SDKs provide idiomatic interfaces for common operations, such as fetching entries, assets, and content types, as well as creating, updating, and deleting content via the CMA. Contentful's approach to SDK development supports a wide range of programming environments, catering to web, mobile, and backend applications.
The Contentful developer documentation provides comprehensive guides and references for each SDK, detailing installation, initialization, and usage patterns for both the Content Delivery API (CDA) and Content Management API (CMA) operations. Developers can find specific examples for retrieving content, managing entries, and handling assets across various programming languages by consulting the Contentful API references.
Official SDKs by language
Contentful maintains official SDKs for a variety of popular programming languages and platforms. These SDKs are developed and supported by Contentful to ensure compatibility with the latest API versions and features. They typically include client libraries for both the CDA (read-only access to published content) and CMA (read/write access for content management).
| Language/Platform | Package Name | Install Command Example | Maturity |
|---|---|---|---|
| JavaScript/TypeScript | contentful (CDA), contentful-management (CMA) |
npm install contentful contentful-management |
Stable |
| Python | contentful (CDA), contentful-management (CMA) |
pip install contentful contentful-management |
Stable |
| Ruby | contentful.rb (CDA), contentful-management.rb (CMA) |
gem install contentful contentful-management |
Stable |
| PHP | contentful/contentful (CDA), contentful/contentful-management (CMA) |
composer require contentful/contentful contentful/contentful-management |
Stable |
| Java | com.contentful.java.cda (CDA), com.contentful.java.cma (CMA) |
Add to pom.xml or build.gradle |
Stable |
| Android | com.contentful.java.cda (CDA), com.contentful.java.cma (CMA) |
Add to build.gradle |
Stable |
| .NET | Contentful.Core (CDA), Contentful.Management.Core (CMA) |
dotnet add package Contentful.Core Contentful.Management.Core |
Stable |
| Swift | Contentful (CDA), ContentfulManagement (CMA) |
Add via Swift Package Manager or CocoaPods | Stable |
| Objective-C | ContentfulDeliveryAPI (CDA), ContentfulManagementAPI (CMA) |
Add via CocoaPods | Stable |
For detailed installation instructions and usage examples for each SDK, developers should refer to the official Contentful developer documentation.
Installation
Installation of Contentful SDKs typically follows the standard package management practices of each respective programming language or platform. For JavaScript/TypeScript, npm or yarn are used. Python projects commonly use pip. Ruby applications rely on Bundler and RubyGems. PHP projects integrate SDKs via Composer. Java and Android projects use Maven or Gradle, while .NET projects utilize NuGet. Swift and Objective-C projects integrate SDKs through Swift Package Manager or CocoaPods.
Example: JavaScript/TypeScript (Node.js/Browser)
To install the Content Delivery API (CDA) and Content Management API (CMA) SDKs for JavaScript/TypeScript environments, use npm:
npm install contentful contentful-management
Example: Python
For Python projects, the SDKs are installed using pip:
pip install contentful contentful-management
Example: PHP
PHP developers can add the Contentful SDKs to their projects using Composer:
composer require contentful/contentful contentful/contentful-management
Each SDK's specific documentation provides detailed prerequisites and setup instructions. For instance, the Contentful JavaScript SDK getting started guide offers comprehensive steps for web-based development.
Quickstart example
This quickstart example demonstrates how to fetch entries from the Contentful Content Delivery API (CDA) using the JavaScript SDK. It assumes you have an active Contentful space with content and have obtained your Space ID and Content Delivery API access token.
import { createClient } from 'contentful';
// Replace with your actual Space ID and Access Token
const SPACE_ID = 'YOUR_CONTENTFUL_SPACE_ID';
const ACCESS_TOKEN = 'YOUR_CONTENTFUL_CDA_ACCESS_TOKEN';
const client = createClient({
space: SPACE_ID,
accessToken: ACCESS_TOKEN,
});
async function fetchContent() {
try {
const entries = await client.getEntries({
content_type: 'blogPost', // Replace with your content type ID
'fields.slug[in]': 'my-first-blog-post' // Optional: filter by slug
});
if (entries.items.length > 0) {
console.log('Fetched entries:', entries.items[0].fields);
} else {
console.log('No entries found.');
}
} catch (error) {
console.error('Error fetching content:', error);
}
}
fetchContent();
This snippet initializes the Contentful client with your credentials and then uses the getEntries method to retrieve content. The content_type parameter is used to specify which type of content to fetch, and additional parameters like 'fields.slug[in]' can be used for filtering. For more advanced queries and content modeling, refer to the Contentful Content Delivery API reference.
Community libraries
In addition to the official SDKs, the Contentful ecosystem benefits from a variety of community-contributed libraries and tools. These often extend functionality, provide integrations with specific frameworks (e.g., React, Vue, Angular), or offer utilities that simplify common tasks. While not officially supported by Contentful, these libraries can provide valuable solutions for niche use cases or preferred development workflows.
Examples of community contributions often include:
- Framework-specific integrations: Libraries that integrate Contentful data fetching directly into popular frontend frameworks, often providing components or hooks.
- Static site generator plugins: Plugins for tools like Gatsby, Next.js, and Jekyll that pull content from Contentful during build time.
- GraphQL clients: While Contentful supports GraphQL directly, community libraries might offer specialized clients or tools for more advanced GraphQL operations or integrations.
- CLI tools: Command-line interfaces built by the community to automate Contentful-related tasks.
Developers seeking community-driven solutions can explore repositories on platforms like GitHub or consult community forums. For instance, the Google Open Source Guides provide general best practices for engaging with open-source communities, which can be applied when evaluating community-developed Contentful tools. It is advisable to review the maintenance status, documentation, and community activity of any third-party library before incorporating it into a production environment.