SDKs overview

Netlify provides a suite of tools for developers to interact with its platform programmatically, primarily through its official command-line interface (CLI) and language-specific SDKs. These resources enable automation of common tasks such as deploying sites, managing build configurations, and invoking serverless functions. The SDKs are designed to extend the capabilities of the Netlify platform beyond its web interface, facilitating integration into custom development environments and continuous integration/continuous deployment (CI/CD) pipelines.

The core of Netlify's developer experience for programmatic interaction is built around the Netlify CLI tool, which serves as a unified interface for managing projects from the local development environment. While not a traditional SDK in the sense of a client library for a specific API, the CLI exposes the full range of Netlify's capabilities through command-line commands that can be scripted.

Beyond the CLI, Netlify offers official SDKs for specific programming languages, focusing on environments where developers frequently build and deploy applications. These SDKs typically wrap the underlying REST API, providing idiomatic access to Netlify's services within the chosen language. Community-contributed libraries also exist, offering alternative implementations or specialized functionalities not covered by the official offerings.

Official SDKs by language

Netlify maintains official SDKs and tools that provide direct programmatic access to its platform. The primary official SDKs are available for JavaScript (Node.js) and Go, catering to common backend and tooling development needs. The Netlify CLI itself is a significant component, built using JavaScript, and is the recommended tool for local development, deployment, and management.

Netlify CLI

The Netlify CLI is a command-line tool that allows developers to deploy sites, manage Netlify Functions, configure redirects, and more, directly from their terminal. It is built with Node.js and serves as the foundational programmatic interface for most Netlify interactions. Its features include:

  • Local Development Server: Emulates the Netlify production environment for local testing.
  • Deployment: Initiates deployments of sites and functions.
  • Functions Management: Develop, test, and deploy Netlify Functions.
  • Addon Management: Manages Netlify add-ons.
  • DNS Management: Configures custom DNS settings.

JavaScript (Node.js)

The official Netlify JavaScript client provides an interface for interacting with the Netlify API from Node.js applications. This client is often used for building custom automation scripts, integrating Netlify into larger Node.js-based applications, or developing tools that interact with the Netlify platform programmatically.

  • Package: netlify
  • Maturity: Stable, actively maintained.
  • Features: API access for sites, deploys, functions, users, and more.

Go

Netlify also provides an official Go client library, which is suitable for developers building applications or tools in Go that need to interact with the Netlify API. This is particularly useful for backend services, custom CI/CD integrations, or command-line utilities written in Go.

  • Package: github.com/netlify/open-api/go/porcelain
  • Maturity: Stable, actively maintained.
  • Features: Comprehensive API coverage for managing Netlify resources.

Below is a table summarizing the official SDKs and their key attributes:

Language Package/Tool Installation Command Maturity
JavaScript (CLI) netlify-cli npm install -g netlify-cli Stable
JavaScript (Client) netlify npm install netlify Stable
Go github.com/netlify/open-api/go/porcelain go get github.com/netlify/open-api/go/porcelain Stable

Installation

Installation procedures for Netlify's official SDKs and tools vary by language and package manager. The following outlines the typical steps for the primary offerings.

Netlify CLI

The Netlify CLI is distributed as an npm package and can be installed globally using npm or yarn. A global installation allows the netlify command to be accessible from any directory in your terminal.

npm install -g netlify-cli
# or
yarn global add netlify-cli

After installation, you can verify it by running netlify --version. To authenticate the CLI with your Netlify account, use netlify login, which will open a browser window for authentication.

JavaScript Client Library

The Netlify JavaScript client library is also an npm package and should be installed as a dependency within your Node.js project.

npm install netlify
# or
yarn add netlify

Once installed, you can import and use it in your JavaScript or TypeScript files:

import NetlifyAPI from 'netlify'

const client = new NetlifyAPI('YOUR_NETLIFY_ACCESS_TOKEN');

Access tokens can be generated from your Netlify user settings.

Go Client Library

The Netlify Go client library is installed using the Go module system. You can add it to your project's dependencies with the go get command.

go get github.com/netlify/open-api/go/porcelain

After fetching the module, you can import and use it in your Go code:

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/netlify/open-api/go/porcelain"
)

func main() {
	accessToken := os.Getenv("NETLIFY_ACCESS_TOKEN")
	if accessToken == "" {
		fmt.Println("NETLIFY_ACCESS_TOKEN environment variable not set")
		return
	}

	client := porcelain.New(accessToken)

	// Example: List sites
	sites, _, err := client.ListSites(context.Background(), nil)
	if err != nil {
		fmt.Printf("Error listing sites: %v\n", err)
		return
	}
	fmt.Println("Netlify Sites:")
	for _, site := range sites {
		fmt.Printf("- %s (ID: %s)\n", *site.Name, *site.ID)
	}
}

Quickstart example

This quickstart example demonstrates how to use the Netlify CLI to deploy a simple static website. This process involves initializing a project, building it (if necessary), and deploying it to Netlify.

Prerequisites:

  • Node.js and npm installed.
  • Netlify CLI installed globally (npm install -g netlify-cli).
  • A Netlify account and logged in via netlify login.

Steps:

1. Create a simple static site

Create a new directory for your project and add an index.html file:

mkdir my-netlify-site
cd my-netlify-site
echo '<!DOCTYPE html><html><head><title>My Netlify Site</title></head><body><h1>Hello from Netlify!</h1></body></html>' > index.html

2. Initialize Netlify project (optional for simple sites)

For more complex sites or to link to a Git repository, you would run netlify init. For a basic static deploy, netlify deploy can infer settings.

3. Deploy the site

Use the netlify deploy command. For a production deployment, use the --prod flag. Without --prod, it creates a deploy preview.

netlify deploy --prod --dir=.

The --dir=. flag specifies that the current directory contains the deployable assets. The CLI will guide you through linking to an existing Netlify site or creating a new one. Once complete, it will provide a URL to your live site.

The output will resemble:

? Link this directory to an existing Netlify site or create a new one? Create & configure a new site
? Site name (optional): my-unique-site-name

Deploying "my-unique-site-name" to Netlify...
✔ Finished deploying! 
Deployed to https://my-unique-site-name.netlify.app

This demonstrates a fundamental workflow for deploying a static site using the Netlify CLI, illustrating how the tool simplifies the deployment process from the command line, one of the key benefits of modern web tooling.

Community libraries

Beyond Netlify's official SDKs and CLI, the developer community has created several libraries and tools that extend or integrate with the Netlify platform. These community-driven projects can offer specialized functionalities, alternative language bindings, or integrations with other ecosystems.

It is important to note that community libraries may not carry the same level of official support, maintenance guarantees, or security auditing as Netlify's officially provided tools. Developers considering these libraries should review their documentation, community activity, and licensing terms.

Examples of areas where community libraries often emerge include:

  • Specific Framework Integrations: Libraries tailored for frameworks like React, Vue, or Angular to simplify deployments or function development beyond what the official CLI offers out-of-the-box.
  • Build Plugins: Custom Netlify Build plugins that perform specific tasks during the build process, such as image optimization, sitemap generation, or advanced caching strategies. While Netlify provides a framework for build plugins, many are community-contributed.
  • API Wrappers in Other Languages: Although Netlify offers official Go and Node.js clients, community members sometimes create wrappers for other languages (e.g., Python, Ruby, PHP) to interact with the Netlify API.
  • Local Development Enhancements: Tools that enhance the local development experience with Netlify Functions or Edge Functions, providing additional debugging capabilities or local testing environments.

To discover community libraries and plugins, developers typically consult:

  • The Netlify Build Plugins directory.
  • GitHub (searching for netlify and relevant programming languages or frameworks).
  • Community forums and discussions (e.g., Netlify's official community forums).

When incorporating a community library, verifying its active maintenance and compatibility with current Netlify platform features is recommended due to the rapid evolution of web technologies.