SDKs overview

CloudConvert offers a suite of official Software Development Kits (SDKs) designed to streamline interaction with its file conversion API. These SDKs are available for multiple programming languages, abstracting the underlying RESTful API calls and managing aspects such as authentication, request construction, and response handling. The goal of these libraries is to reduce the development effort required to integrate CloudConvert's conversion capabilities into various applications and services.

The CloudConvert API itself is documented as a RESTful interface, supporting standard HTTP methods and JSON payloads for requests and responses. Developers can interact with the API directly using any HTTP client, but the SDKs provide a more idiomatic approach for each supported language. This includes helper functions for common operations like creating conversion jobs, adding tasks, and managing webhooks.

The SDKs aim to provide a consistent developer experience across languages, reflecting the API's design principles. They are maintained by CloudConvert and are generally kept up-to-date with new API features and changes. The availability of these SDKs is a key component of CloudConvert's developer experience, simplifying the process of embedding file conversion functionality.

Official SDKs by language

CloudConvert provides official SDKs for several popular programming languages, each designed to integrate seamlessly with the CloudConvert API v2. These libraries encapsulate the API's functionality, allowing developers to manage conversion jobs, tasks, and webhooks using native language constructs. The following table details the official SDKs, their respective package managers, and installation commands.

Language Package Name Installation Command Maturity
PHP cloudconvert/cloudconvert composer require cloudconvert/cloudconvert Stable
Node.js cloudconvert npm install cloudconvert or yarn add cloudconvert Stable
Python cloudconvert-python pip install cloudconvert-python Stable
Ruby cloudconvert gem install cloudconvert Stable
Go github.com/cloudconvert/cloudconvert-go go get github.com/cloudconvert/cloudconvert-go Stable
Java com.cloudconvert:cloudconvert-java Maven: Add dependency to pom.xml. Gradle: Add dependency to build.gradle. Stable

Installation

Installing a CloudConvert SDK typically involves using the standard package manager for the chosen programming language. The process is designed to be straightforward, allowing developers to quickly add the library to their project dependencies. Below are detailed installation instructions for the primary supported languages.

PHP

For PHP projects, the CloudConvert SDK is distributed via Composer, the dependency manager for PHP. To install:

composer require cloudconvert/cloudconvert

After installation, Composer's autoloader can be included in your project to make the SDK classes available.

Node.js

The Node.js SDK is available through npm or yarn. To install in your Node.js project:

npm install cloudconvert
# or
yarn add cloudconvert

This command adds the cloudconvert package to your node_modules directory and updates your package.json file.

Python

Python developers can install the CloudConvert SDK using pip, the Python package installer:

pip install cloudconvert-python

This command will download and install the necessary Python package and its dependencies.

Ruby

For Ruby applications, the CloudConvert SDK is distributed as a Gem. To install:

gem install cloudconvert

After installation, the gem can be required in your Ruby script or Gemfile.

Go

Go developers can retrieve the CloudConvert SDK using the go get command:

go get github.com/cloudconvert/cloudconvert-go

This command fetches the package and its dependencies, making them available for import in Go source files.

Java

The Java SDK for CloudConvert is available through Maven Central. For Maven projects, add the following dependency to your pom.xml file:

<dependency>
    <groupId>com.cloudconvert</groupId>
    <artifactId>cloudconvert-java</artifactId>
    <version>2.x.x</version> <!-- Use the latest version -->
</dependency>

For Gradle projects, add the dependency to your build.gradle file:

implementation 'com.cloudconvert:cloudconvert-java:2.x.x' // Use the latest version

Ensure to replace 2.x.x with the latest stable version of the CloudConvert Java SDK.

Quickstart example

The following quickstart example demonstrates how to use the CloudConvert Node.js SDK to convert a PDF file to a JPG image. This example covers authenticating with your API key, creating a new conversion job, adding tasks to upload the input file, perform the conversion, and then export the output file.

Before running this example, ensure you have installed the Node.js SDK (npm install cloudconvert) and replaced YOUR_API_KEY with your actual CloudConvert API key. You can find your API key on the CloudConvert API documentation for authentication.

const cloudconvert = new (require('cloudconvert'))({
    api_key: 'YOUR_API_KEY',
    sandbox: true // Set to false for production
});

(async () => {
    try {
        const job = await cloudconvert.jobs.create({
            "tasks": {
                "upload-my-file": {
                    "operation": "import/url",
                    "url": "https://cloudconvert.com/api/v2/docs/downloads/sample.pdf"
                },
                "convert-my-file": {
                    "operation": "convert",
                    "input": "upload-my-file",
                    "output_format": "jpg",
                    "quality": 80
                },
                "export-my-file": {
                    "operation": "export/url",
                    "input": "convert-my-file"
                }
            }
        });

        const finishedJob = await cloudconvert.jobs.wait(job.id);

        const file = cloudconvert.jobs.getExportUrls(finishedJob)[0];

        console.log('Conversion successful. Download URL:', file.url);

        // You can then download the file using a library like 'node-fetch' or 'axios'
        // const response = await fetch(file.url);
        // const buffer = await response.buffer();
        // require('fs').writeFileSync('output.jpg', buffer);

    } catch (error) {
        console.error('Conversion failed:', error);
    }
})();

This script first initializes the CloudConvert client with your API key. It then defines a job with three tasks: importing a sample PDF from a URL, converting it to a JPG with a specified quality, and exporting the resulting JPG to a downloadable URL. The jobs.wait() method polls the API until the job is completed, and then the export URL is extracted and logged. This demonstrates a typical workflow for file conversion using the SDK.

Community libraries

While CloudConvert provides official SDKs for several major programming languages, the open nature of its RESTful API allows for the development of community-contributed libraries. These libraries can offer support for languages not officially covered, alternative implementations, or specialized features tailored to specific use cases. Developers often publish such libraries on package managers or code hosting platforms like GitHub.

Community libraries may vary in terms of maintenance, feature completeness, and adherence to the latest API versions. Before incorporating a community-developed SDK, it is advisable to review its documentation, check its activity on its repository, and assess its compatibility with the current CloudConvert API v2 specification. The Mozilla Developer Network's API glossary provides a general understanding of how APIs function, which is useful when evaluating any third-party library's interaction with a given API.

As of the last review, CloudConvert's official documentation primarily highlights its own maintained SDKs. However, developers interested in contributing to or finding community-driven projects can often search public code repositories or community forums for additional tools. The CloudConvert team encourages developers to use the official documentation as the authoritative source for API specifications when evaluating any community-contributed code.