SDKs overview

SerpApi provides Software Development Kits (SDKs) and client libraries to facilitate programmatic access to its search engine results APIs. These SDKs are language-specific packages that encapsulate the logic for making API requests, handling authentication, and parsing the JSON responses from SerpApi's various search endpoints. By using an SDK, developers can integrate SerpApi's functionalities into their applications with fewer lines of code and reduced boilerplate compared to making raw HTTP requests.

The SDKs are designed to abstract away the underlying HTTP communication, allowing developers to focus on the data they need from search engines like Google, Bing, Baidu, and others. This includes managing API keys, constructing query parameters, and processing structured JSON output for various search types, such as organic results, images, shopping, and local listings. SerpApi maintains official SDKs for several popular programming languages, while a community of developers contributes additional libraries and tools.

These libraries typically handle common tasks such as URL encoding of parameters, retries for transient network errors, and consistent error handling, which contributes to a more stable and efficient integration. For example, a Python SDK might offer a GoogleSearch object that takes parameters as keyword arguments and returns a Python dictionary representing the JSON response, simplifying data access for Python developers. The official SerpApi documentation provides detailed guides and examples for each supported SDK, illustrating how to perform various search queries and extract specific data points from the results.

Official SDKs by language

SerpApi offers official SDKs for a range of programming languages, ensuring broad compatibility for developers. These SDKs are maintained by SerpApi and are designed to provide stable and up-to-date integration with the API. Each SDK typically includes methods for initiating search queries, passing parameters, and retrieving results in a structured format, usually JSON.

The official SDKs are available through standard package managers for each language, simplifying the installation and dependency management process. This approach allows developers to quickly add SerpApi functionality to their projects without manual configuration of API endpoints or request headers. The maturity column in the table below reflects the current development status and maintenance level for each library, with most official SDKs being actively maintained and stable for production use.

Language Package Name Install Command Maturity
Python google-search-results pip install google-search-results Stable
Ruby google-search-results gem install google-search-results Stable
Node.js google-search-results npm install google-search-results Stable
PHP serpapi/google-search-results composer require serpapi/google-search-results Stable
Java com.serpapi/google-search-results Maven / Gradle dependency Stable
C# SerpApi.GoogleSearchResults dotnet add package SerpApi.GoogleSearchResults Stable
Go github.com/serpapi/google-search-results-go go get github.com/serpapi/google-search-results-go Stable

Each of these SDKs provides a consistent interface for interacting with the SerpApi service, abstracting the underlying HTTP requests and JSON parsing. Developers can refer to the SerpApi documentation for client libraries for specific usage instructions and examples tailored to each language.

Installation

Installing SerpApi SDKs typically involves using the standard package manager for each respective programming language. This ensures that all necessary dependencies are resolved and the library is correctly integrated into your project environment. The process is generally straightforward, requiring a single command in your terminal or command prompt.

Python

For Python, the pip package installer is used. Open your terminal and run:

pip install google-search-results

This command downloads and installs the official Python client library, making its functionalities available for import in your Python scripts.

Ruby

Ruby projects use gem for package management. To install the SerpApi Ruby gem, execute:

gem install google-search-results

After installation, you can require the gem in your Ruby application to start making API calls.

Node.js

For Node.js applications, npm (Node Package Manager) is the standard tool. Navigate to your project directory and run:

npm install google-search-results

This command adds the SerpApi Node.js library to your project's node_modules folder and updates your package.json file.

PHP

PHP projects typically use Composer for dependency management. To install the SerpApi PHP client, run:

composer require serpapi/google-search-results

This will add the library to your project and generate an autoloader for easy inclusion.

Java

For Java, you'll need to add the dependency to your project's build file (e.g., pom.xml for Maven or build.gradle for Gradle). The specific dependency configuration can be found on the SerpApi Java client library documentation.

Example for Maven (pom.xml):

  <dependencies>
    <dependency>
      <groupId>com.serpapi</groupId>
      <artifactId>google-search-results</artifactId>
      <version>2.0.0</version> <!-- Check for the latest version -->
    </dependency>
  </dependencies>

C#

C# projects use NuGet for package management. In your project directory or Visual Studio's Package Manager Console, run:

dotnet add package SerpApi.GoogleSearchResults

This command integrates the SerpApi C# library into your .NET project.

Go

For Go projects, use the go get command to fetch the module:

go get github.com/serpapi/google-search-results-go

After running this, the module will be available for import in your Go source files.

It's important to always refer to the official SerpApi documentation for the most up-to-date installation instructions and version compatibility for each SDK.

Quickstart example

This quickstart example demonstrates how to use the SerpApi Python SDK to perform a simple Google search and print the results. This pattern is generally consistent across other language SDKs, with minor syntactical differences.

Python Quickstart

First, ensure you have installed the Python SDK using pip install google-search-results. You will also need your SerpApi API key, which can be found in your SerpApi dashboard.

from serpapi import GoogleSearch
import os

# Set your API key from environment variables or directly (not recommended for production)
# os.environ["SERPAPI_API_KEY"] = "YOUR_API_KEY"

# Define the search parameters
params = {
    "api_key": os.getenv("SERPAPI_API_KEY"), # Ensure this environment variable is set
    "engine": "google",
    "q": "SerpApi SDKs",
    "gl": "us", # Country code for the search
    "hl": "en", # Language code for the search
}

# Initialize the GoogleSearch object and get the results
try:
    search = GoogleSearch(params)
    results = search.get_json()

    # Print organic results titles and links
    if "organic_results" in results:
        print("\nOrganic Results:")
        for result in results["organic_results"]:
            print(f"Title: {result.get('title')}")
            print(f"Link: {result.get('link')}\n")
    else:
        print("No organic results found.")

    # Optionally, print other sections like related questions
    if "related_questions" in results:
        print("\nRelated Questions:")
        for question in results["related_questions"]:
            print(f"- {question.get('question')}")

except Exception as e:
    print(f"An error occurred: {e}")

This example initializes a GoogleSearch object with the specified parameters, including the API key, search engine, query, and geo-location/language settings. It then retrieves the JSON results and iterates through the organic_results section to print the title and link of each result. This foundational structure can be extended to access other data points available in the SerpApi JSON response, such as knowledge graphs, ads, local results, and more, as detailed in the SerpApi Search API reference.

For security, it is recommended to store your API key as an environment variable rather than hardcoding it directly into your script. This practice helps prevent accidental exposure of sensitive credentials, a principle broadly recommended for API integrations across various platforms, as detailed in Google's API key security best practices.

Community libraries

Beyond the officially maintained SDKs, the developer community has created additional libraries and tools that interact with the SerpApi platform. These community-contributed resources can offer alternative approaches, support for less common languages, or specialized functionalities not present in the official SDKs. While not officially supported by SerpApi, they can be valuable for specific use cases or development preferences.

Community libraries often emerge in response to developer demand for integrations in particular frameworks or with specific design patterns. They might provide wrappers for languages where an official SDK is not yet available or offer extensions that simplify common tasks for a niche audience. Developers interested in exploring these options should be aware that community projects may have varying levels of maintenance and support. It is advisable to review the project's documentation, GitHub repository activity, and community feedback before integrating them into production systems.

For instance, developers might find community-driven wrappers for languages like Rust or Dart, or integrations with specific web frameworks that streamline data fetching and display. These libraries typically adhere to the same API request and response structure as the official SDKs, but their internal implementation and feature sets can differ. The SerpApi documentation portal sometimes lists popular community contributions, or developers can discover them through public code repositories and developer forums. When using a community library, always ensure it is compatible with the latest SerpApi API version and review its security practices, especially regarding API key handling.