SDKs overview

Contentful offers a suite of Software Development Kits (SDKs) designed to streamline interaction with its Composable Content Platform. These SDKs abstract the underlying RESTful and GraphQL APIs, allowing developers to focus on application logic rather than direct HTTP requests and response parsing. The primary SDKs are categorized into Content Delivery SDKs (for retrieving published content) and Content Management SDKs (for creating, updating, and deleting content).

The SDKs are available for a range of popular programming languages and environments, ensuring broad compatibility across different development stacks. Contentful maintains official SDKs for core languages and frameworks, while the developer community contributes additional libraries and tools. This dual approach provides both robust, officially supported integrations and a wider ecosystem of specialized solutions, as detailed in the Contentful SDKs documentation.

Contentful's approach aligns with modern API design principles, providing both RESTful API interactions and GraphQL queries for flexible data fetching. The SDKs encapsulate these methods, making it easier to integrate content into web, mobile, and other digital experiences.

Official SDKs by language

Contentful provides officially supported SDKs for several programming languages, covering both client-side content delivery and server-side content management operations. These SDKs are maintained by Contentful and are recommended for most production environments. Each SDK typically includes methods for authenticating with the Contentful API, querying content types, entries, and assets, and handling errors.

The following table outlines the official SDKs, their respective package identifiers, and typical installation commands:

Language Package Name Installation Command Maturity
JavaScript (Node.js/Browser) contentful npm install contentful Stable
TypeScript contentful (with type definitions) npm install contentful --save Stable
Python contentful pip install contentful Stable
Ruby contentful.rb gem install contentful.rb Stable
PHP contentful/contentful composer require contentful/contentful Stable
Java com.contentful.java:contentful-delivery Maven/Gradle dependency Stable
Android com.contentful.java:contentful-android Gradle dependency Stable
.NET (C#) Contentful.Management.Sdk, Contentful.Core dotnet add package Contentful.Core Stable
iOS (Objective-C) ContentfulDeliveryAPI CocoaPods/Carthage Stable
Swift Contentful Swift Package Manager/CocoaPods Stable

Installation

Installation procedures vary slightly depending on the programming language and package manager used. However, the general process involves adding the Contentful SDK as a dependency to your project.

JavaScript/TypeScript (Node.js & Browser)

For JavaScript and TypeScript projects, the contentful package is installed via npm or yarn:

npm install contentful
# or
yarn add contentful

This package supports both Content Delivery API (CDA) and Content Management API (CMA) operations. The Contentful JavaScript SDK documentation provides further setup details.

Python

Python developers can install the Contentful SDK using pip:

pip install contentful

The Contentful Python SDK guide includes examples for both delivery and management operations.

Ruby

The Ruby SDK is available as a gem:

gem install contentful.rb

Refer to the Ruby SDK getting started guide for integration steps.

PHP

PHP projects typically use Composer for dependency management:

composer require contentful/contentful

The Contentful PHP SDK documentation details usage with Symfony, Laravel, and other frameworks.

Java & Android

For Java and Android applications, dependencies are typically managed through Maven or Gradle. For Content Delivery, you would add:

// Maven
<dependency>
    <groupId>com.contentful.java</groupId>
    <artifactId>contentful-delivery</artifactId>
    <version>X.Y.Z</version>
</dependency>

// Gradle
implementation 'com.contentful.java:contentful-delivery:X.Y.Z'

Replace X.Y.Z with the latest Java SDK version. For Android, use contentful-android.

.NET (C#)

The .NET SDK is installed via NuGet:

dotnet add package Contentful.Core
# or via Package Manager Console
Install-Package Contentful.Core

The Contentful .NET SDK documentation covers both delivery and management SDKs.

iOS (Objective-C) & Swift

iOS and Swift projects often use Swift Package Manager, CocoaPods, or Carthage. For Swift Package Manager:

dependencies: [
    .package(url: "https://github.com/contentful/contentful.swift.git", .upToNextMajor(from: "X.Y.Z"))
]

For CocoaPods, add to your Podfile:

pod 'Contentful', '~> X.Y'

Consult the Contentful iOS/Swift SDK guide for versioning and detailed setup instructions.

Quickstart example

This quickstart example demonstrates how to fetch content using the JavaScript Content Delivery SDK. This typically involves initializing the client with your Space ID and Content Delivery API (CDA) access token, then making a query for entries.

First, ensure you have your Contentful Space ID and CDA access token. These credentials are required to authenticate your requests and retrieve content from your Contentful space. You can find these in your Contentful account settings under API keys.

JavaScript Example (Node.js)

const contentful = require('contentful');

const client = contentful.createClient({
  space: 'YOUR_SPACE_ID',
  accessToken: 'YOUR_CDA_ACCESS_TOKEN'
});

client.getEntries({
  content_type: 'blogPost',
  'fields.slug': 'my-first-blog-post'
})
  .then((response) => {
    if (response.items.length > 0) {
      const entry = response.items[0];
      console.log('Fetched entry:', entry.fields.title);
      console.log('Body:', entry.fields.body);
    } else {
      console.log('No entries found.');
    }
  })
  .catch(console.error);

This example initializes a Contentful client and then uses client.getEntries() to fetch entries of a specific content type (blogPost) with a particular slug. The response is an array of entries, from which the first item's title and body fields are logged. Error handling is included via a .catch() block.

Community libraries

Beyond the officially supported SDKs, the Contentful developer community has contributed various libraries and tools that extend functionality or provide integrations with specific frameworks and platforms. These community projects can offer solutions for niche use cases, experimental features, or alternative approaches to content interaction.

While not officially maintained by Contentful, these libraries can be valuable resources. Developers should evaluate their active maintenance, documentation quality, and community support before incorporating them into production systems. Common types of community contributions include:

  • Framework-specific integrations: Libraries that simplify integrating Contentful with popular front-end frameworks like React, Vue.js, or Angular, often providing components or hooks.
  • GraphQL clients: Tools that enhance GraphQL query building and execution specifically for Contentful's GraphQL API.
  • Static site generators: Connectors for static site generators (e.g., Gatsby, Next.js, Hugo) to pull content during build processes.
  • Utility libraries: Helper functions for common tasks like image transformations, rich text rendering, or webhook processing.

A comprehensive list of community-contributed tools and integrations can typically be found within the Contentful developer documentation's references section or on community forums and GitHub. It is advisable to check the project's repository for its current status and support model.