SDKs overview

Kong API Gateway offers various software development kits (SDKs) and client libraries designed to facilitate programmatic interaction with its Admin API. These SDKs enable developers to automate the configuration and management of Kong Gateway instances, including defining services, routes, consumers, and plugins. The primary use case for these libraries is to integrate Kong's management capabilities into CI/CD pipelines, custom tooling, or other automation scripts. While Kong Gateway itself is written in Lua and Nginx Kong Gateway architecture overview, its SDKs are available in common programming languages to support a broad developer ecosystem.

The Admin API is a RESTful interface that allows for complete control over a Kong Gateway deployment Kong Gateway Admin API reference. SDKs abstract the HTTP requests and responses, providing language-specific objects and methods to interact with this API, simplifying tasks such as adding new APIs, managing traffic policies, or updating security configurations. This programmatic approach supports the infrastructure-as-code paradigm, allowing gateway configurations to be version-controlled and deployed consistently.

Official SDKs by language

Kong maintains official client libraries for several popular programming languages. These libraries are developed and supported by Kong, ensuring compatibility with the latest Admin API versions and adherence to best practices. The official SDKs typically offer a comprehensive set of features mirroring the full capabilities of the Admin API.

Language Package/Module Installation Command Maturity/Status
Go github.com/kong/go-kong/kong go get github.com/kong/go-kong/kong Actively maintained
Java com.konghq:kong-java-client Maven: Add dependency to pom.xml | Gradle: Add dependency to build.gradle Actively maintained
Python python-kong pip install python-kong Actively maintained
JavaScript (Node.js) @kong/kong-js-sdk npm install @kong/kong-js-sdk or yarn add @kong/kong-js-sdk Actively maintained

Installation

Installation methods for Kong's official SDKs follow standard practices for each respective programming language ecosystem. Developers typically use package managers to add the client libraries to their projects.

Go

To install the Go client for Kong Gateway, use the go get command:

go get github.com/kong/go-kong/kong

This command downloads the package and its dependencies, making it available for import in your Go project Go client library reference.

Java

For Java projects, the Kong client is available via Maven Central. You would typically add it as a dependency in your pom.xml (for Maven) or build.gradle (for Gradle).

Maven

<dependency>
    <groupId>com.konghq</groupId>
    <artifactId>kong-java-client</artifactId>
    <version>2.x.x</version> <!-- Replace with the latest version -->
</dependency>

Gradle

implementation 'com.konghq:kong-java-client:2.x.x' // Replace with the latest version

Refer to the official Kong Java client documentation Kong Java client documentation for the latest version number and usage details.

Python

The Python client can be installed using pip, the standard package installer for Python:

pip install python-kong

This command installs the python-kong package, enabling you to interact with the Kong Admin API from your Python applications Python client library details. It is recommended to use a virtual environment for project-specific dependencies.

JavaScript (Node.js)

For Node.js environments, install the JavaScript SDK using npm or yarn:

npm

npm install @kong/kong-js-sdk

yarn

yarn add @kong/kong-js-sdk

Once installed, you can import the module into your JavaScript or TypeScript projects to manage Kong Gateway JavaScript client library guide.

Quickstart example

This Python example demonstrates how to use the python-kong library to connect to a Kong Admin API, list existing services, and create a new service. This assumes Kong Gateway is running and its Admin API is accessible (e.g., at http://localhost:8001).

from kong import Kong

# Initialize the Kong client
# Replace with your Kong Admin API URL if different
kong_admin_url = "http://localhost:8001"
k = Kong(kong_admin_url)

print(f"Connecting to Kong Admin API at: {kong_admin_url}")

try:
    # List existing services
    print("\n--- Existing Services ---")
    services = k.services.list()
    if services['data']:
        for service in services['data']:
            print(f"  Service ID: {service['id']}, Name: {service['name']}, Host: {service['host']}")
    else:
        print("  No services found.")

    # Define a new service
    new_service_name = "my-example-service"
    new_service_host = "mockbin.org"
    new_service_path = "/request"

    # Check if the service already exists to avoid errors
    try:
        existing_service = k.services.retrieve(new_service_name)
        print(f"\nService '{new_service_name}' already exists. Skipping creation.")
    except Exception as e:
        if "Not found" in str(e):
            print(f"\nCreating new service: {new_service_name}")
            created_service = k.services.create(
                name=new_service_name,
                host=new_service_host,
                port=80,
                protocol="http",
                path=new_service_path
            )
            print(f"  Created Service ID: {created_service['id']}, Name: {created_service['name']}")
        else:
            raise e # Re-raise other unexpected errors

    # Verify the new service is in the list
    print("\n--- Services After Creation Attempt ---")
    services_after = k.services.list()
    for service in services_after['data']:
        print(f"  Service ID: {service['id']}, Name: {service['name']}, Host: {service['host']}")

except Exception as e:
    print(f"An error occurred: {e}")
    print("Please ensure Kong Gateway is running and its Admin API is accessible at the specified URL.")

This script first initializes a client connection to the Kong Admin API. It then fetches and prints a list of all currently configured services. Following this, it attempts to create a new service named my-example-service pointing to mockbin.org/request, but only if a service with that name does not already exist. Finally, it lists all services again to show the updated configuration. This example demonstrates basic CRUD (Create, Read, Update, Delete) operations using the SDK, which is a common pattern for automating API gateway management Kong Admin API services endpoint. Further details on Python SDK capabilities can be found in the official Python client documentation.

Community libraries

Beyond the officially supported SDKs, the Kong community has developed various tools and libraries that interact with Kong Gateway. These community contributions often address specific niches, offer alternative language bindings, or integrate Kong with other ecosystem tools. While not officially supported by Kong, they can provide valuable functionality and extend Kong's usability in diverse development environments.

  • Terraform Provider for Kong: The Terraform Provider for Kong allows developers to manage Kong Gateway configurations using HashiCorp Terraform. This enables infrastructure-as-code principles for Kong, defining services, routes, plugins, and consumers in declarative configuration files Terraform documentation. It's widely used for automating deployments and maintaining consistent configurations across environments.
  • Kong Ingress Controller for Kubernetes: While not strictly an SDK, the Kong Ingress Controller is a significant community-driven (now official and supported by Kong) project that allows Kong Gateway to function as an Ingress controller within Kubernetes clusters. It translates Kubernetes Ingress resources into Kong Gateway configurations, effectively managing API traffic for microservices deployed on Kubernetes.
  • Unofficial Clients: Various unofficial client libraries in languages not covered by official SDKs may exist on platforms like GitHub. These are typically developed and maintained by individual community members. Developers evaluating such libraries should consider their maintenance status, last update, and community activity.

When using community-contributed tools, it is advisable to review their documentation, issue trackers, and community support channels to assess their reliability and ongoing development. The Kong community forums and GitHub repositories are good places to discover and discuss these contributions Kong Community Resources.