SDKs overview

Resend provides Software Development Kits (SDKs) to facilitate integration with its email API. These libraries abstract the underlying HTTP requests and authentication mechanisms, allowing developers to interact with the Resend service using familiar programming language patterns. The primary function of these SDKs is to enable programmatic sending of emails, but they also support other API functionalities such as domain management and audience segmentation. Resend's approach prioritizes developer experience, aiming for a clean and intuitive API surface, particularly for teams utilizing the React ecosystem for email templating via React Email integration.

The official SDKs are maintained by Resend and are designed to provide stable and feature-complete access to the API. Community libraries, while not officially supported, offer alternative language bindings or specialized functionalities developed by the broader developer community. Integrating an SDK typically involves installing the package via a language-specific package manager, initializing the client with an API key, and then calling methods to perform desired operations.

Official SDKs by language

Resend offers official SDKs for several popular programming languages, ensuring direct and supported integration pathways for a wide range of development environments. These SDKs are designed to follow the conventions of their respective languages, providing a native development experience. Below is a summary of the official SDKs available:

Language Package Name Install Command (npm/pip/gem/composer/go get) Maturity Documentation
Node.js resend npm install resend or yarn add resend Stable Resend Node.js SDK documentation
Python resend-python pip install resend Stable Resend Python SDK documentation
Ruby resend-ruby gem install resend-ruby Stable Resend Ruby SDK documentation
PHP resend/resend-php composer require resend/resend-php Stable Resend PHP SDK documentation
Go github.com/resend/resend-go go get github.com/resend/resend-go Stable Resend Go SDK documentation

Installation

Installing a Resend SDK typically involves using the standard package manager for the respective programming language. Each SDK is published to its language's official package repository, facilitating straightforward dependency management and updates. Before installation, developers should ensure they have the correct runtime environment and package manager configured. For example, Node.js projects require npm or Yarn, Python projects use pip, and PHP projects use Composer.

Node.js

npm install resend
# or
yarn add resend

Python

pip install resend

Ruby

gem install resend-ruby

PHP

composer require resend/resend-php

Go

go get github.com/resend/resend-go

After installation, the next step is to obtain an API key from the Resend dashboard. This key is essential for authenticating API requests made through the SDK. Best practices dictate storing API keys securely, typically as environment variables, rather than hardcoding them directly into application source code. This approach enhances security and simplifies key rotation.

Quickstart example

The following examples demonstrate how to send a basic email using the Resend SDKs in Node.js, Python, PHP, Ruby, and Go. These snippets illustrate the core functionality of initializing the client and making a simple email sending request. The RESERVED_RESEND_API_KEY placeholder should be replaced with an actual API key obtained from your Resend account.

Node.js Quickstart

import { Resend } from 'resend';

const resend = new Resend(process.env.RESERVED_RESEND_API_KEY);

(async function() {
  try {
    const { data, error } = await resend.emails.send({
      from: 'Acme <[email protected]>',
      to: ['[email protected]'],
      subject: 'Hello World from Node.js SDK',
      html: '<strong>It works!</strong>',
    });

    if (error) {
      console.error({ error });
      return;
    }

    console.log({ data });
  } catch (error) {
    console.error({ error });
  }
})();

Python Quickstart

import os
from resend import Resend

resend = Resend(api_key=os.environ.get("RESERVED_RESEND_API_KEY"))

params = {
    "from": "Acme <[email protected]>",
    "to": ["[email protected]"],
    "subject": "Hello World from Python SDK",
    "html": "<strong>It works!</strong>",
}

email = resend.emails.send(params)
print(email)

PHP Quickstart

use Resend\Resend;

require_once __DIR__ . '/vendor/autoload.php';

$resend = new Resend(getenv('RESERVED_RESEND_API_KEY'));

try {
    $result = $resend->emails->send([
        'from' => 'Acme <[email protected]>',
        'to' => ['[email protected]'],
        'subject' => 'Hello World from PHP SDK',
        'html' => '<strong>It works!</strong>',
    ]);

    print_r($result);
} catch (\Exception $e) {
    echo 'Error: ' . $e->getMessage();
}

Ruby Quickstart

require 'resend'

Resend.api_key = ENV['RESERVED_RESEND_API_KEY']

begin
  email = Resend::Emails.send(
    from: 'Acme <[email protected]>',
    to: ['[email protected]'],
    subject: 'Hello World from Ruby SDK',
    html: '<strong>It works!</strong>'
  )
  puts email
rescue StandardError => e
  puts "Error: #{e.message}"
end

Go Quickstart

package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/resend/resend-go"
)

func main() {
	resendKey := os.Getenv("RESERVED_RESEND_API_KEY")
	if resendKey == "" {
		log.Fatal("RESERVED_RESEND_API_KEY environment variable is not set")
	}

	client := resend.NewClient(resendKey)

	sendEmailRequest := &resend.SendEmailRequest{
		From:    "Acme <[email protected]>",
		To:      []string{"[email protected]"},
		Subject: "Hello World from Go SDK",
		Html:    "<strong>It works!</strong>",
	}

	_, err := client.Emails.Send(context.TODO(), sendEmailRequest)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println("Email sent successfully!")
}

These examples illustrate the minimal code required to send an email. For more advanced features, such as sending emails with attachments, custom headers, or utilizing React Email templates, developers should consult the specific documentation for each SDK.

Community libraries

Beyond the officially supported SDKs, the Resend ecosystem benefits from community-contributed libraries. These libraries can offer integrations with frameworks not officially covered, provide alternative abstractions, or address niche use cases. While not directly maintained by Resend, community libraries can extend the reach and flexibility of the Resend API for developers working in specific environments or with particular preferences.

Examples of community contributions often include:

  • Framework-specific integrations: Libraries that integrate Resend with web frameworks like Laravel (for PHP), Django/Flask (for Python), or Ruby on Rails, providing helper methods or service providers that align with the framework's conventions.
  • Client libraries in other languages: Support for languages not yet covered by official SDKs. For instance, a community might develop a client for C# or Java.
  • Specialized tools: Utilities for specific tasks, such as webhook handlers or email template generators that integrate with Resend.

Developers interested in using community libraries should exercise due diligence, reviewing the library's documentation, GitHub repository activity, and community support. The Resend community SDKs page often lists such projects, providing a starting point for discovery. It is important to note that the stability, security, and ongoing maintenance of community-driven projects can vary compared to official vendor-supported SDKs, as is common with open-source contributions. The Mozilla Developer Network's glossary entry on open source provides further context on the nature of community-driven software.