SDKs overview

Screenshot offers a range of Software Development Kits (SDKs) and libraries designed to facilitate integration with its API. These SDKs are language-specific wrappers that abstract the underlying HTTP requests and response parsing, enabling developers to incorporate screenshot functionality into their applications more efficiently. The core functionality provided by these SDKs includes capturing full-page screenshots, customizing resolutions, emulating different devices, and managing various output formats Screenshot API documentation. Developers can utilize these tools to automate tasks such as generating website thumbnails, archiving web pages, or monitoring visual changes on websites.

The SDKs aim to reduce development time by providing idiomatic interfaces for each supported language, handling aspects like authentication, request parameter serialization, and error handling. This allows developers to focus on application logic rather than the intricacies of API communication. While official SDKs are maintained by Screenshot, community-contributed libraries may also exist, offering alternative implementations or specialized functionalities. The choice between an official SDK and a community library often depends on specific project requirements, language preferences, and the level of community support available for the library Mozilla Developer Network SDK definition.

Official SDKs by language

Screenshot provides official SDKs for several popular programming languages, ensuring direct support and compatibility with the API's features. These SDKs are developed and maintained by Screenshot to guarantee adherence to the API's specifications and to offer a consistent developer experience across different environments. The table below outlines the officially supported languages, their respective package names, installation commands, and a general indication of their maturity based on official documentation.

Language Package/Library Name Install Command Maturity
Node.js screenshotapi-node npm install screenshotapi-node or yarn add screenshotapi-node Stable
Python screenshotapi-python pip install screenshotapi-python Stable
Ruby screenshotapi-ruby gem install screenshotapi-ruby Stable
PHP screenshotapi-php composer require screenshotapi/screenshotapi-php Stable
Go screenshotapi-go go get github.com/screenshotapi/screenshotapi-go Stable
Java screenshotapi-java Add to pom.xml (Maven) or build.gradle (Gradle) Stable
C# screenshotapi-csharp dotnet add package ScreenshotAPI.CSharp Stable
Rust screenshotapi-rust Add to Cargo.toml Stable

Each SDK provides specific methods and objects that mirror the API's endpoints and parameters, allowing for a more intuitive development experience. For detailed API methods and parameter specifications, refer to the official Screenshot documentation.

Installation

Installing Screenshot SDKs typically follows standard package management practices for each programming language. The process generally involves adding the SDK as a dependency to your project using a command-line tool or by manually configuring your project's build system. Below are general installation instructions for the most commonly used languages, which correspond to the primary language examples provided by Screenshot.

Node.js Installation

For Node.js projects, the SDK can be installed via npm (Node Package Manager) or Yarn:

npm install screenshotapi-node
# or
yarn add screenshotapi-node

After installation, you can import the library into your JavaScript or TypeScript files:

const ScreenshotAPI = require('screenshotapi-node');
// For ES modules:
// import ScreenshotAPI from 'screenshotapi-node';

Python Installation

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

pip install screenshotapi-python

Once installed, the library can be imported into your Python scripts:

import screenshotapi_python

PHP Installation

For PHP projects, Composer is the recommended tool for dependency management:

composer require screenshotapi/screenshotapi-php

After running the command, Composer will generate an autoloader file that you need to include in your project:

<?php
require 'vendor/autoload.php';
use ScreenshotAPI\Client;
?>

For other languages like Ruby, Go, Java, C#, and Rust, the installation processes involve their respective package managers (e.g., Bundler for Ruby Gems, Go Modules for Go, Maven/Gradle for Java, NuGet for C#, and Cargo for Rust). Specific instructions for each can be found in the Screenshot API documentation for SDKs.

Quickstart example

This section provides a basic quickstart example using the Node.js SDK to demonstrate how to capture a screenshot. The example illustrates the typical workflow: initializing the client with your API key, specifying the URL to capture, and then executing the screenshot request. Ensure you replace YOUR_API_KEY with your actual API key obtained from your Screenshot account dashboard.

const ScreenshotAPI = require('screenshotapi-node');

const API_KEY = 'YOUR_API_KEY'; // Replace with your actual API Key
const client = new ScreenshotAPI(API_KEY);

const targetUrl = 'https://www.example.com';

client.screenshot(targetUrl, {
  full_page: true, // Capture the entire page
  output: 'json', // Get JSON response with image URL
  width: 1920, // Desired width of the screenshot
  height: 1080, // Desired height of the screenshot (for non-full-page)
  format: 'png' // Output format: png, jpeg, webp
})
.then(response => {
  console.log('Screenshot captured successfully!');
  console.log('Image URL:', response.screenshot);
  // Example of accessing other data in the response
  // console.log('HTML:', response.html);
  // console.log('Title:', response.title);
})
.catch(error => {
  console.error('Error capturing screenshot:', error.message);
  if (error.response && error.response.data) {
    console.error('API Error Details:', error.response.data);
  }
});

This snippet initializes the Screenshot client and makes a request to capture a full-page screenshot of https://www.example.com, returning a JSON response that includes the URL of the generated image. The full_page, output, width, and format parameters demonstrate some of the customization options available. Developers can adjust these parameters to suit specific needs, such as capturing a specific viewport size, requesting a different image format, or even applying custom CSS to the page before capture. For a complete list of configurable options, consult the Screenshot API parameter reference.

Community libraries

While Screenshot provides official SDKs, the broader developer community may contribute unofficial libraries or integrations. These community-driven projects can offer specialized functionalities, alternative language support, or integrations with specific frameworks not covered by official SDKs. Community libraries typically emerge from developers' needs to extend or adapt API interactions for unique use cases or preferred development environments. For example, a community library might provide a wrapper optimized for a particular web framework like React or Vue, or offer advanced features like automated retry mechanisms or caching layers.

Discovering community libraries often involves searching public code repositories like GitHub or discussions on developer forums. It is important to note that community libraries may vary in terms of maintenance, documentation quality, and overall stability compared to officially supported SDKs. Developers considering a community library should evaluate its active development, issue tracking, and community support before integrating it into production environments. The GitHub topics for screenshot API projects can be a starting point for exploring such community contributions, though direct endorsement or support from Screenshot for these projects is not implied. Always review the source code and licensing of any third-party library before use to ensure it meets project requirements and security standards.

When selecting between an official SDK and a community-contributed library, developers often weigh factors such as the maturity of the codebase, the frequency of updates, the availability of comprehensive documentation, and the responsiveness of the maintainers. Official SDKs typically offer a higher guarantee of compatibility and support directly from the API provider. However, community libraries can sometimes provide innovative solutions or fill niche requirements that official SDKs might not prioritize. For critical applications, relying on an official SDK is generally recommended due to the direct support channel and guaranteed compatibility with API updates Google API Client Library Guidelines.