SDKs overview

Duply provides Software Development Kits (SDKs) and client libraries to simplify interaction with its REST API. These SDKs abstract the underlying HTTP requests, authentication mechanisms, and response parsing, allowing developers to integrate Duply's AI-powered image generation and editing capabilities into their applications with language-specific constructs. The primary goal of these libraries is to reduce boilerplate code and potential errors when consuming the Duply API, which offers features like AI product photography and automated background removal.

The SDKs are designed to mirror the API's structure, providing methods for tasks such as uploading images, applying transformations, generating new images based on prompts, and retrieving processed assets. This approach aligns with common practices for exposing web services, where client libraries enhance developer experience by handling network communication details as described by cloud service providers. Duply's official documentation provides detailed guides and examples for each supported language, ensuring developers can quickly get started with image processing workflows.

Official SDKs by language

Duply offers official SDKs for several popular programming languages, ensuring broad compatibility with existing development stacks. These SDKs are maintained by Duply and are the recommended method for integrating with the platform's API endpoints. Each SDK provides a consistent interface, allowing developers to switch between languages while maintaining a similar understanding of how to interact with Duply's services.

The following table lists the currently available official SDKs, their respective package names, installation commands, and maturity status:

Language Package Name Installation Command Maturity
Node.js @duply/duply-sdk npm install @duply/duply-sdk Stable
Python duply-sdk pip install duply-sdk Stable
PHP duply/duply-sdk composer require duply/duply-sdk Stable
Ruby duply-sdk gem install duply-sdk Stable
Go github.com/duply/duply-sdk-go go get github.com/duply/duply-sdk-go Stable

These SDKs are designed to abstract common tasks such as API key management, request signing, and error handling, making the integration process more efficient. For instance, the Node.js SDK facilitates asynchronous operations, consistent with JavaScript's event-driven nature, while the Python SDK integrates seamlessly with common data science and web development frameworks.

Installation

Installing Duply's official SDKs involves using the standard package manager for each respective programming language. Each SDK is distributed via its language's primary package repository, ensuring ease of access and version management. Before installation, developers should ensure they have the correct language runtime and package manager installed.

Node.js

For Node.js projects, the SDK is available via npm. Navigate to your project directory and execute the following command:

npm install @duply/duply-sdk

This command adds the @duply/duply-sdk package as a dependency in your package.json file and downloads it into your node_modules directory. You can then import it into your JavaScript or TypeScript files using require or import statements.

Python

Python developers can install the Duply SDK using pip, the Python package installer. Open your terminal or command prompt and run:

pip install duply-sdk

This command fetches the duply-sdk package from PyPI. It is often recommended to use a virtual environment for Python projects to manage dependencies effectively. Information on Python virtual environments is available in the official Python documentation.

PHP

The PHP SDK for Duply is managed through Composer, the dependency manager for PHP. In your project root, execute:

composer require duply/duply-sdk

Composer will add the duply/duply-sdk entry to your composer.json and download the necessary files. Ensure Composer is installed and accessible in your environment before running this command. You will then need to include Composer's autoloader in your PHP scripts.

Ruby

Ruby applications use RubyGems for package management. To install the Duply SDK, run:

gem install duply-sdk

This command installs the duply-sdk gem. After installation, you can require the gem in your Ruby scripts to access its functionalities. Developers often manage Ruby project dependencies using Bundler, which involves adding gem 'duply-sdk' to your Gemfile and then running bundle install.

Go

For Go projects, the SDK can be obtained using the go get command. From your project's module, run:

go get github.com/duply/duply-sdk-go

This command downloads the Go module into your module cache. You can then import it into your Go source files using import "github.com/duply/duply-sdk-go". Go modules simplify dependency management, ensuring consistent builds.

Quickstart example

This quickstart example demonstrates how to use the Duply Python SDK to perform a basic operation: uploading an image and requesting a background removal. Before running this code, ensure you have installed the Python SDK as described in the Installation section and have your Duply API key ready. You can obtain an API key from your Duply account dashboard.

Python Background Removal Example

First, save an image file (e.g., product.jpg) in the same directory as your Python script. This example assumes a simple synchronous operation.

import duply_sdk
import os

# Replace with your actual Duply API Key
DUPLY_API_KEY = os.environ.get("DUPLY_API_KEY", "YOUR_DUPLY_API_KEY")

def main():
    if DUPLY_API_KEY == "YOUR_DUPLY_API_KEY":
        print("Please set your DUPLY_API_KEY environment variable or replace the placeholder.")
        return

    client = duply_sdk.Client(api_key=DUPLY_API_KEY)

    image_path = "product.jpg"
    output_path = "product_no_bg.png"

    if not os.path.exists(image_path):
        print(f"Error: Image file not found at {image_path}")
        print("Please ensure 'product.jpg' exists in the current directory.")
        return

    try:
        print(f"Uploading {image_path} and requesting background removal...")
        # Example: Upload image and request background removal
        result = client.images.upload_and_process(
            file=open(image_path, 'rb'),
            process_type="background_removal",
            output_format="png" # Specify output format
        )

        if result and result.get('processed_image_url'):
            processed_image_url = result['processed_image_url']
            print(f"Background removed image URL: {processed_image_url}")

            # Optionally, download the processed image
            import requests
            response = requests.get(processed_image_url)
            if response.status_code == 200:
                with open(output_path, 'wb') as f:
                    f.write(response.content)
                print(f"Processed image saved to {output_path}")
            else:
                print(f"Failed to download processed image: {response.status_code}")
        else:
            print("Background removal request failed or returned no processed image URL.")
            if result and result.get('error'):
                print(f"API Error: {result['error']}")

    except duply_sdk.ApiException as e:
        print(f"Duply API Error: {e}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

if __name__ == "__main__":
    main()

This script initializes the Duply client with your API key, then calls the upload_and_process method, specifying background_removal as the desired processing type. It then prints the URL of the processed image and attempts to download it, saving it locally. This illustrates a common workflow for automated image manipulation, a core capability of Duply's AI-powered services.

Community libraries

While Duply provides official SDKs for the most commonly used programming languages, the open-source community may also develop and maintain additional libraries or integrations. These community-contributed libraries often extend functionality, provide integrations with specific frameworks, or offer support for languages not covered by official SDKs. Community libraries can be found on platforms like GitHub, GitLab, or through language-specific package registries.

When considering community-developed libraries, it is important to evaluate their maintenance status, documentation quality, and active community support. Developers should review the source code, check for recent commits, and examine issue trackers to gauge the reliability and security of such third-party integrations. Duply's official documentation and community forums (if available) are good places to look for mentions or recommendations of community contributions. While official SDKs are vetted and supported by Duply, community libraries offer flexibility and innovation, sometimes addressing niche use cases or providing alternative architectural patterns. For example, a community library might offer a wrapper for a specific web framework like Django or Ruby on Rails, streamlining the integration further than a general-purpose SDK. However, they typically do not carry the same level of support or guarantees as the vendor's own offerings.