SDKs overview

Tyk provides Software Development Kits (SDKs) and libraries designed to facilitate programmatic interaction with its API management platform. These tools primarily support extending the functionality of the Tyk API Gateway through custom plugins and offer interfaces for managing administrative tasks, such as API definition and user management. The SDKs abstract away direct HTTP request construction and response parsing, allowing developers to focus on business logic rather than low-level API communication. Tyk's approach emphasizes extensibility, enabling developers to integrate the gateway into diverse application architectures, including microservices and serverless environments. The official SDKs are developed and maintained by Tyk, while a broader ecosystem of community-contributed libraries also exists. Developers can find comprehensive documentation for these tools, including API references and usage guides, on the Tyk documentation portal.

Official SDKs by language

Tyk offers official SDKs for three primary programming languages: Go, Python, and Node.js. These SDKs are maintained by Tyk and are designed to provide stable and feature-rich interfaces for common integration patterns. The choice of language often depends on the existing technology stack and developer preference. Each SDK provides specific functionalities tailored to its language ecosystem, while collectively aiming to cover core Tyk extensibility and management capabilities. The Go SDK is frequently used for developing custom plugins due to Go's performance characteristics and suitability for concurrent network applications. The Python and Node.js SDKs offer flexibility for scripting and integrating Tyk with broader application logic. For detailed API specifications and SDK-specific functions, developers should consult the Tyk API Gateway API reference.

Official Tyk SDKs

Language Package Name Primary Use Cases Maturity
Go go-tyk-plugin (for plugins), Tyk Gateway API Client Custom middleware plugins, Gateway extensions Stable
Python tyk-python (community, but widely used for custom auth) Custom authentication, rich transformations Stable (community-driven for specific use cases)
Node.js tyk-plugin-kit (for plugins) Custom middleware plugins, event handlers Stable

Installation

Installation of Tyk SDKs typically involves using the respective language's package manager. The process is straightforward, enabling developers to quickly set up their development environments. Each SDK may have specific dependencies, which are usually managed automatically by the package manager. For developing custom Go plugins, the Go module system is utilized, requiring a Go development environment. Python installations leverage pip, while Node.js projects use npm or yarn. It is recommended to create isolated development environments (e.g., Python virtual environments or Node.js project-local installations) to prevent dependency conflicts. Detailed installation instructions and prerequisites are available in the Tyk plugin documentation for each language.

Go SDK Installation (for plugins)

go mod init myplugin
go get github.com/TykTechnologies/tyk/go-plugin

This command initializes a new Go module and fetches the Tyk Go plugin library, enabling the development of custom middleware.

Python Installation (for custom authentication)

pip install tyk-python

This command installs the tyk-python package, which is commonly used to implement custom authentication logic within the Tyk gateway.

Node.js SDK Installation (for plugins)

npm init -y
npm install tyk-plugin-kit

These commands initialize a Node.js project and install the tyk-plugin-kit, providing the necessary tools for building Node.js-based plugins.

Quickstart example

The following quickstart example demonstrates a basic Go plugin that modifies an HTTP header for all requests passing through the Tyk Gateway. This illustrates the fundamental structure of a Tyk custom plugin, which intercepts requests or responses, applies logic, and then passes them along the chain. This type of plugin development allows for highly customizable gateway behavior without modifying the core Tyk source code. The plugin is compiled into a shared library and loaded by the Tyk Gateway, acting as a middleware component. For deployment, the compiled plugin needs to be placed where the Tyk Gateway can access it, and the API definition must be configured to use the plugin. More complex examples, including those demonstrating external API calls or data transformations, are available in the Tyk Go plugin examples.

Go Plugin Example: Adding a Custom Header

package main

import (
	"log"
	"github.com/TykTechnologies/tyk/go-plugin/proto"
	"github.com/TykTechnologies/tyk/go-plugin/comms"
)

// MyPlugin is the struct that will hold our plugin logic
type MyPlugin struct{}

// NewMyPlugin creates a new instance of MyPlugin
func NewMyPlugin() interface{} {
	return &MyPlugin{}
}

// MyPreHook is a pre-request hook that adds a custom header
func (m *MyPlugin) MyPreHook(request *proto.HttpRequest, session *proto.SessionState, config map[string]string, perAPIConfig map[string]string) (*proto.HttpRequest, *proto.SessionState, error) {
	log.Println("Executing MyPreHook")
	// Add a custom header to the request
	if request.Header == nil {
		request.Header = make(map[string]*proto.StringList)
	}
	request.Header["X-Custom-Header"] = &proto.StringList{Value: []string{"Tyk-Go-Plugin"}}

	return request, session, nil
}

// Init is called once when the plugin is loaded
func Init(gateway *comms.Gateway)
{
  log.Println("Go plugin initialized")
}

func main() {}

To compile this plugin:

go build -buildmode=plugin -o myplugin.so myplugin.go

After compilation, the myplugin.so file can be loaded by the Tyk Gateway. Configuration within the Tyk Dashboard would then associate this plugin with a specific API endpoint or global policy. This example demonstrates a simple request modification, but Tyk plugins can perform a wide range of operations, including complex authentication schemes, data validation, and response transformations. Further details on plugin configuration can be found in the Tyk Go plugins guide.

Community libraries

Beyond the officially supported SDKs, the Tyk community has developed various libraries and tools that extend its functionality or simplify integrations. These community-contributed resources often address niche use cases, provide language bindings for less common programming languages, or offer higher-level abstractions for specific Tyk features. While not officially supported by Tyk, these libraries can be valuable for developers looking for specific functionalities or alternative approaches. Developers should evaluate community libraries based on their activity, documentation quality, and compatibility with their Tyk version. Resources like GitHub and public forums serve as primary discovery platforms for these projects. For example, some developers use community-maintained tools to integrate Tyk with Continuous Integration/Continuous Deployment (CI/CD) pipelines or to automate dashboard configurations that are not directly covered by official SDKs. For general best practices when integrating with API gateways, the Google Cloud API Gateway best practices provide useful context.

Examples of community contributions include:

  • Tyk client libraries in other languages: Unofficial wrappers for the Tyk Dashboard API or Gateway API written for languages like Ruby, PHP, or Java.
  • Configuration management tools: Scripts or utilities that interact with Tyk's API to manage API definitions, policies, and users programmatically, often used in infrastructure-as-code scenarios.
  • Monitoring and logging integrations: Custom exporters or connectors that push Tyk metrics or logs to third-party monitoring systems not natively supported.

Developers are encouraged to explore the Tyk community contributions section within the official documentation and various open-source repositories for these additional resources. When using community-driven projects, it is advisable to review the source code and documentation thoroughly to ensure reliability and security.