SDKs overview

Glitterly provides a RESTful API for developers to programmatically generate images from pre-defined templates. The API facilitates tasks such as creating dynamic social media graphics, personalized marketing visuals, and e-commerce product images at scale. To streamline integration, Glitterly offers official Software Development Kits (SDKs) that abstract the underlying HTTP requests and response handling, allowing developers to interact with the API using native language constructs.

SDKs simplify common API operations, including template fetching, data submission for image rendering, and retrieving generated image URLs. For languages without official SDKs, community-contributed libraries or direct HTTP client usage can be employed to interact with the Glitterly API endpoints. The core functionality revolves around sending data payloads to a specific template endpoint and receiving image URLs in response, which can then be used or stored.

While the Glitterly API documentation provides comprehensive details on available endpoints and parameters for image generation, SDKs aim to reduce the boilerplate code required for these interactions. This includes handling API key authentication, request formatting, and error parsing. Developers can refer to the official Glitterly API documentation for a complete list of endpoints and their specifications.

Official SDKs by language

Glitterly maintains official SDKs for popular programming languages, designed to offer a consistent and developer-friendly experience. These SDKs are developed and supported by Glitterly to ensure compatibility with the latest API versions and features. They typically handle serialization and deserialization of data, HTTP request management, and API key authentication, reducing the need for developers to manage these aspects manually.

The following table outlines the officially supported SDKs, including their respective package names and typical installation commands:

Language Package Name Install Command Maturity
Python glitterly-python pip install glitterly-python Stable
Node.js @glitterly/node npm install @glitterly/node Stable

These SDKs are designed to align with their respective language conventions, offering an idiomatic approach to interacting with the Glitterly API. For detailed usage instructions and method references, developers should consult the specific SDK documentation provided on the Glitterly developer portal.

Installation

Installing Glitterly SDKs involves using the standard package managers for each programming language. Before installation, ensure you have the correct language runtime and package manager set up in your development environment.

Python SDK

The Glitterly Python SDK requires Python 3.7 or higher. Installation is performed using pip, the Python package installer.

pip install glitterly-python

After installation, you can import the library into your Python projects. It is recommended to use a virtual environment to manage dependencies for your project, as outlined in the Python virtual environment tutorial.

Node.js SDK

The Glitterly Node.js SDK requires Node.js 14 or higher. Installation is performed using npm, the Node.js package manager.

npm install @glitterly/node

Alternatively, if you are using Yarn:

yarn add @glitterly/node

Once installed, you can import the module into your JavaScript or TypeScript projects. More details on Node.js package management can be found on the npm install documentation.

Quickstart example

This section provides a quickstart example using the Glitterly Node.js SDK to generate an image from a template. This example assumes you have already installed the Node.js SDK and have your Glitterly API Key and a Template ID ready. You can find your API Key in your Glitterly account settings and create or select a Template ID from your Glitterly dashboard.

Node.js Quickstart

First, create a JavaScript file (e.g., generate-image.js) and add the following code:

const Glitterly = require('@glitterly/node');

const API_KEY = 'YOUR_GLITTERLY_API_KEY'; // Replace with your actual API Key
const TEMPLATE_ID = 'YOUR_TEMPLATE_ID'; // Replace with your actual Template ID

const glitterly = new Glitterly(API_KEY);

async function generateImage() {
  try {
    const response = await glitterly.createImage({
      templateId: TEMPLATE_ID,
      modifications: {
        text_title: 'Hello, Glitterly!',
        image_profile: 'https://example.com/profile.jpg', // URL to an image asset
        color_accent: '#FF5733'
      },
      output: {
        format: 'png',
        quality: 80
      }
    });

    console.log('Image generated successfully!');
    console.log('Image URL:', response.url);
    // You can now download or display this URL

  } catch (error) {
    console.error('Error generating image:', error.message);
    if (error.response && error.response.data) {
      console.error('API Error details:', error.response.data);
    }
  }
}

generateImage();

Before running the script, ensure you replace 'YOUR_GLITTERLY_API_KEY' and 'YOUR_TEMPLATE_ID' with your actual credentials. The modifications object should correspond to the dynamic fields defined within your Glitterly template. For instance, if your template has a text layer named text_title, you would pass its new value here.

To execute the script, open your terminal in the directory where you saved generate-image.js and run:

node generate-image.js

The script will output the URL of the newly generated image if successful. This URL can then be used to display, download, or further process the image.

Python Quickstart

For Python, the process is similar. Create a Python file (e.g., generate_image.py) and add the following code:

from glitterly import Glitterly
import os

API_KEY = os.getenv('GLITTERLY_API_KEY', 'YOUR_GLITTERLY_API_KEY')
TEMPLATE_ID = 'YOUR_TEMPLATE_ID' # Replace with your actual Template ID

glitterly = Glitterly(API_KEY)

def generate_image():
    try:
        response = glitterly.create_image(
            template_id=TEMPLATE_ID,
            modifications={
                'text_title': 'Python with Glitterly!',
                'image_logo': 'https://example.com/logo.png',
                'color_background': '#1A73E8'
            },
            output={
                'format': 'jpeg',
                'quality': 90
            }
        )

        print('Image generated successfully!')
        print('Image URL:', response['url'])

    except Exception as e:
        print(f'Error generating image: {e}')

if __name__ == '__main__':
    generate_image()

Remember to replace placeholder values and ensure your modifications dictionary matches your template's dynamic fields. Running this script will produce the image URL in the console.

Community libraries

Beyond the officially supported SDKs, the Glitterly API's RESTful nature allows for integration with any programming language capable of making HTTP requests. This has enabled the developer community to create and maintain unofficial libraries for various languages.

These community-contributed libraries often aim to provide similar convenience to official SDKs, wrapping API calls in language-specific constructs. While not officially supported by Glitterly, they can be valuable resources for developers working in languages like PHP, Ruby, or Go.

Examples of community-driven efforts might include:

  • PHP Client Libraries: Often distributed via Packagist, these libraries would allow PHP developers to interact with the Glitterly API using Composer.
  • Ruby Gems: For Ruby developers, a gem would provide a Ruby-idiomatic way to make API calls, installed via Bundler.

When using community libraries, it is important to verify their maintenance status, compatibility with the latest Glitterly API version, and security practices. Developers might find these libraries on platforms like GitHub or package repositories specific to each language. For unsupported languages, developers can always directly consume the Glitterly REST API using standard HTTP client libraries (e.g., requests in Python, axios or fetch in JavaScript, Guzzle in PHP) by following the official API documentation and managing authentication with their API key manually.