SDKs overview

EasyPost provides Software Development Kits (SDKs) and client libraries designed to facilitate interaction with its shipping and logistics API. These SDKs abstract the underlying HTTP requests and JSON responses, allowing developers to integrate shipping functionalities directly into their applications using familiar programming language constructs. The primary goal of these libraries is to expedite development by providing ready-to-use functions for common tasks such as creating shipments, purchasing labels, tracking packages, and verifying addresses.

The official EasyPost SDKs are maintained by EasyPost and are available for several widely used programming languages. They encapsulate the API's authentication mechanisms, error handling, and data serialization/deserialization, ensuring consistent and reliable communication with the EasyPost platform. By using an SDK, developers can focus on their application's business logic rather than on the intricacies of RESTful API consumption. This approach is common among API providers to improve developer experience, as also observed in the offerings of other services like Stripe's API documentation and Twilio's SDKs for various languages.

Official SDKs by language

EasyPost maintains official SDKs for a range of programming languages, ensuring broad compatibility for developers. These SDKs are designed to provide idiomatic interfaces for interacting with the EasyPost API. Each SDK typically includes client classes for the core API resources, such as shipments, addresses, and tracking events. Developers can find detailed documentation for each language-specific SDK, including examples and usage guides on the EasyPost developer documentation portal.

The table below outlines the officially supported SDKs, their respective package managers, and typical installation commands. These packages are regularly updated to reflect new API features and ensure compatibility with current language versions.

Language Package Manager / Name Installation Command Maturity
Ruby easypost (RubyGems) gem install easypost Stable
Python easypost (pip) pip install easypost Stable
PHP easypost/easypost-php (Composer) composer require easypost/easypost-php Stable
Node.js @easypost/api (npm) npm install @easypost/api Stable
Java com.easypost/easypost-api-java (Maven/Gradle) Maven: Add dependency; Gradle: implementation 'com.easypost:easypost-api-java:VERSION' Stable
Go github.com/EasyPost/easypost-go (go get) go get github.com/EasyPost/easypost-go/v2 Stable
C# / .NET EasyPost (NuGet) dotnet add package EasyPost Stable

Installation

Installing an EasyPost SDK typically involves using the standard package manager for your chosen programming language. This ensures that all necessary dependencies are resolved and the library is correctly integrated into your project. Below are detailed installation steps for the most commonly used SDKs:

Python

To install the Python SDK, use pip, the Python package installer:

pip install easypost

After installation, you can verify it by importing the library in a Python interpreter or script:

import easypost
print(easypost.__version__)

Node.js

For Node.js projects, the SDK is available via npm:

npm install @easypost/api

You can then require or import the module in your JavaScript/TypeScript files:

const EasyPost = require('@easypost/api');
// or
import EasyPost from '@easypost/api';

Ruby

The Ruby SDK is distributed as a Rubygem. Install it using the gem command:

gem install easypost

Include it in your Ruby application by adding require 'easypost' to your code, or by adding gem 'easypost' to your Gemfile and running bundle install.

PHP

PHP projects typically use Composer for dependency management. To add the EasyPost PHP SDK:

composer require easypost/easypost-php

Ensure you include Composer's autoloader in your script: require 'vendor/autoload.php';.

Java

For Java projects using Maven, add the EasyPost Java SDK dependency to your pom.xml:

<dependency>
  <groupId>com.easypost</groupId>
  <artifactId>easypost-api-java</artifactId>
  <version>YOUR_VERSION_HERE</version>
</dependency>

If you're using Gradle, add to your build.gradle:

implementation 'com.easypost:easypost-api-java:YOUR_VERSION_HERE'

Go

To install the Go SDK, use the go get command:

go get github.com/EasyPost/easypost-go/v2

Then, import it into your Go source files:

import "github.com/EasyPost/easypost-go/v2"

C# / .NET

For .NET applications, install the SDK via NuGet Package Manager:

dotnet add package EasyPost

Alternatively, use the NuGet Package Manager UI in Visual Studio to search for EasyPost and install.

Quickstart example

This quickstart example demonstrates how to create a simple shipment and purchase a shipping label using the EasyPost Python SDK. This process generally involves setting your API key, defining sender and recipient addresses, specifying package details, and then creating and purchasing the shipment.

Python Quickstart: Creating and Purchasing a Label

import easypost

# 1. Set your EasyPost API key
# Replace 'YOUR_EASYPOST_API_KEY' with your actual production or test API key.
# You can find your API key in your EasyPost dashboard.
easypost.api_key = 'YOUR_EASYPOST_API_KEY'

try:
    # 2. Define sender address (from_address)
    from_address = easypost.Address.create(
        street1='417 Montgomery St',
        street2='Floor 5',
        city='San Francisco',
        state='CA',
        zip='94104',
        country='US',
        company='EasyPost',
        phone='415-456-7890'
    )

    # 3. Define recipient address (to_address)
    to_address = easypost.Address.create(
        street1='164 Townsend Street',
        street2='Unit 1',
        city='San Francisco',
        state='CA',
        zip='94107',
        country='US',
        company='EasyPost',
        phone='415-123-4567'
    )

    # 4. Define package details
    parcel = easypost.Parcel.create(
        length=20.2,
        width=10.9,
        height=5.0,
        weight=20.0 # Weight in ounces
    )

    # 5. Create a shipment object with addresses and parcel
    shipment = easypost.Shipment.create(
        to_address=to_address,
        from_address=from_address,
        parcel=parcel,
        # Optionally, specify carriers or service levels
        # carrier_accounts=['ca_...'], # Replace with your carrier account ID
        # service=['USPSPriorityMail']
    )

    # 6. Buy the cheapest rate for the shipment
    # This will automatically select the lowest cost available rate and purchase the label.
    shipment.buy(rate=shipment.lowest_rate())

    # 7. Print the label URL and tracking code
    print(f"Label URL: {shipment.postage_label.label_url}")
    print(f"Tracking Code: {shipment.tracking_code}")
    print(f"Carrier: {shipment.selected_rate.carrier}")
    print(f"Service: {shipment.selected_rate.service}")
    print(f"Cost: {shipment.selected_rate.rate}")

except easypost.Error as e:
    print(f"Error creating shipment: {e}")
    for error_detail in e.errors:
        print(f"  Field: {error_detail['field']}, Message: {error_detail['message']}")

This example initializes the EasyPost client with an API key, creates 'from' and 'to' addresses, defines a parcel, and then generates and purchases a shipping label. Replace 'YOUR_EASYPOST_API_KEY' with your actual test or production API key from your EasyPost API Keys section. The shipment.lowest_rate() method dynamically selects the most economical shipping option available for the given parameters, demonstrating a core EasyPost feature for multi-carrier rate shopping.

Community libraries

While EasyPost provides a comprehensive set of official SDKs, the developer community occasionally contributes additional libraries or integrations. These community-maintained resources can sometimes offer specialized functionalities, alternative language support, or tailored solutions for specific frameworks not officially covered. Examples might include wrappers for less common languages, integrations with specific e-commerce platforms, or tools for data migration and analytics related to EasyPost data.

Developers exploring community libraries should exercise caution and verify the source, maintenance status, and security practices of such projects. Unofficial libraries may not always keep pace with the latest API changes or maintain the same level of support as the official SDKs. For critical production systems, relying on and contributing to the official SDKs is generally recommended due to their direct support from EasyPost and adherence to API specifications. Relevant information on community contributions or discussions can sometimes be found in public repositories on platforms like GitHub or developer forums, but EasyPost's official documentation does not explicitly list them. For the most up-to-date and supported integration, refer to the official EasyPost developer documentation.