PHPackages                             easypost/easypost-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. easypost/easypost-php

ActiveLibrary[API Development](/categories/api)

easypost/easypost-php
=====================

EasyPost Shipping API Client Library for PHP

8.7.0(2mo ago)1753.1M—1.9%565MITPHPPHP &gt;=8.1CI passing

Since Nov 8Pushed 2mo ago55 watchersCompare

[ Source](https://github.com/EasyPost/easypost-php)[ Packagist](https://packagist.org/packages/easypost/easypost-php)[ Docs](https://github.com/EasyPost/easypost-php)[ RSS](/packages/easypost-easypost-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (18)Versions (81)Used By (5)

EasyPost PHP Client Library
===========================

[](#easypost-php-client-library)

[![CI](https://github.com/EasyPost/easypost-php/workflows/CI/badge.svg)](https://github.com/EasyPost/easypost-php/actions?query=workflow%3ACI)[![codecov](https://camo.githubusercontent.com/c1d7f471b90f8aad97d74197703023d4279031661eff922ee5dc1845f7842747/68747470733a2f2f636f6465636f762e696f2f67682f45617379506f73742f65617379706f73742d7068702f67726170682f62616467652e7376673f746f6b656e3d52374a376c3453323461)](https://codecov.io/gh/EasyPost/easypost-php)[![PHP version](https://camo.githubusercontent.com/a9f1577235fb962c00d142d777eca0f3c1237f696d538368a7fe813457d256e7/68747470733a2f2f62616467652e667572792e696f2f70682f65617379706f737425324665617379706f73742d7068702e737667)](https://badge.fury.io/ph/easypost%2Feasypost-php)

EasyPost, the simple shipping solution. You can sign up for an account at .

Install
-------

[](#install)

**NOTE:** This library relies on the [mbstring](http://php.net/manual/en/book.mbstring.php) extension. Ensure you have it [installed](http://www.php.net/manual/en/mbstring.installation.php) correctly before using the library.

```
# Install via Composer
composer require easypost/easypost-php
```

```
# Require the autoloader (when using composer - recommended):
require_once("/path/to/vendor/easypost/autoload.php");

# Alternatively, manually download and require the library,
# will require manually downloading and requiring other dependencies:
require_once("/path/to/lib/easypost.php");
```

Usage
-----

[](#usage)

A simple create &amp; buy shipment example:

```
require_once("/path/to/vendor/easypost/autoload.php");

$client = new \EasyPost\EasyPostClient(getenv('EASYPOST_API_KEY'));

$shipment = $client->shipment->create([
    "from_address" => [
        "company" => "EasyPost",
        "street1" => "118 2nd Street",
        "street2" => "4th Floor",
        "city"    => "San Francisco",
        "state"   => "CA",
        "zip"     => "94105",
        "phone"   => "415-456-7890",
    ],
    "to_address" => [
        "name"    => "Dr. Steve Brule",
        "street1" => "179 N Harbor Dr",
        "city"    => "Redondo Beach",
        "state"   => "CA",
        "zip"     => "90277",
        "phone"   => "310-808-5243",
    ],
    "parcel" => [
        "length" => 20.2,
        "width"  => 10.9,
        "height" => 5,
        "weight" => 65.9,
    ],
]);

$boughtShipment = $client->shipment->buy($shipment->id, $shipment->lowestRate());

echo $boughtShipment;
```

### HTTP Hooks

[](#http-hooks)

Users can subscribe to HTTP requests and responses via the `RequestHook` and `ResponseHook` objects. To do so, pass a function to the `subscribeToRequestHook` or `subscribeToResponseHook` methods of an `EasyPostClient` object:

```
function customFunction($args)
{
    // Pass your code here, data about the request/response is contained within `$args`.
    echo "Received a request with the status code of: " . $args['http_status'];
}

$client = new \EasyPost\EasyPostClient(getenv('EASYPOST_API_KEY'));

$client->subscribeToResponseHook('customFunction');

// Make your API calls here, your customFunction will trigger once a response is received
```

You can also unsubscribe your functions in a similar manner by using the `unsubscribeFromRequestHook` and `unsubscribeFromResponseHook` methods of a client object.

Documentation
-------------

[](#documentation)

API documentation can be found at: .

Library documentation can be found on the web at:  or by building them locally via the `just docs` command.

Upgrading major versions of this project? Refer to the [Upgrade Guide](UPGRADE_GUIDE.md).

Support
-------

[](#support)

New features and bug fixes are released on the latest major release of this library. If you are on an older major release of this library, we recommend upgrading to the most recent release to take advantage of new features, bug fixes, and security patches. Older versions of this library will continue to work and be available as long as the API version they are tied to remains active; however, they will not receive updates and are considered EOL.

For additional support, see our [org-wide support policy](https://github.com/EasyPost/.github/blob/main/SUPPORT.md).

Development
-----------

[](#development)

```
# Install dependencies
just install

# Update dependencies
just update

# Lint project
just lint
just lint-fix

# Run tests
EASYPOST_TEST_API_KEY=123... EASYPOST_PROD_API_KEY=123... just test

# Generate coverage reports (requires Xdebug for HTML report)
# NOTE: When using PHP 8.2, you must use 8.2.9+ to avoid segfaults when generating coverage
EASYPOST_TEST_API_KEY=123... EASYPOST_PROD_API_KEY=123... just coverage

# Run security analysis
just scan

# Generate library documentation (requires phpDocumentor.phar in the root of the project)
just docs

# Update submodules
just update-examples-submodule
```

### Testing

[](#testing)

The test suite in this project was specifically built to produce consistent results on every run, regardless of when they run or who is running them. This project uses [VCR](https://github.com/php-vcr/php-vcr) to record and replay HTTP requests and responses via "cassettes". When the suite is run, the HTTP requests and responses for each test function will be saved to a cassette if they do not exist already and replayed from this saved file if they do, which saves the need to make live API calls on every test run. If you receive errors about a cassette expiring, delete and re-record the cassette to ensure the data is up-to-date.

**Sensitive Data:** We've made every attempt to include scrubbers for sensitive data when recording cassettes so that PII or sensitive info does not persist in version control; however, please ensure when recording or re-recording cassettes that prior to committing your changes, no PII or sensitive information gets persisted by inspecting the cassette.

**Making Changes:** If you make an addition to this project, the request/response will get recorded automatically for you when `TestUtil::setupCassette('object/action.yml');` is added to the beginning of a test function. When making changes to this project, you'll need to re-record the associated cassette to force a new live API call for that test which will then record the request/response used on the next run.

**Test Data:** The test suite has been populated with various helpful fixtures that are available for use, each completely independent from a particular user **with the exception of the USPS carrier account ID** (see [Unit Test API Keys](#unit-test-api-keys) for more information) which has a fallback value of our internal testing user's ID. Some fixtures use hard-coded dates that may need to be incremented if cassettes get re-recorded (such as reports or pickups).

#### Unit Test API Keys

[](#unit-test-api-keys)

The following are required on every test run:

- `EASYPOST_TEST_API_KEY`
- `EASYPOST_PROD_API_KEY`

Some tests may require an EasyPost user with a particular set of enabled features such as a `Partner` user when creating referrals. We have attempted to call out these functions in their respective docstrings. The following are required when you need to re-record cassettes for applicable tests:

- `USPS_CARRIER_ACCOUNT_ID` (eg: one-call buying a shipment for non-EasyPost employees)
- `PARTNER_USER_PROD_API_KEY` (eg: creating a referral user)
- `REFERRAL_CUSTOMER_PROD_API_KEY` (eg: adding a credit card to a referral user)

#### Mocking

[](#mocking)

Some of our unit tests require HTTP calls that cannot be easily tested with live/recorded calls (e.g. HTTP calls that trigger payments or interact with external APIs).

We have implemented a custom, lightweight HTTP mocking functionality in this library that allows us to mock HTTP calls and responses.

A mock client is the same as a normal client, with a set of mock request-response pairs stored as a property.

At the time of making a real HTTP request, a mock client will instead check which mock request entry matches the queued request (matching by HTTP method and a regex pattern for the URL), and will return the corresponding mock response (HTTP status code and body).

**NOTE**: If a client is configured with a mocking utility, it will ONLY make mock requests. If it attempts to make a request that does not match any of the configured mock requests, the request will fail and trigger an exception.

To use the mocking utility:

```
use EasyPost\Test\mocking\MockingUtility;
use EasyPost\Test\mocking\MockRequest;
use EasyPost\Test\mocking\MockRequestMatchRule;
use EasyPost\Test\mocking\MockRequestResponseInfo;

// create a mocking utility with a list of mock request-response pairs
$mockingUtility = new MockingUtility(
    new MockRequest(
        new MockRequestMatchRule(
            // HTTP method and regex pattern for the URL must both pass for the request to match
            'post',
            '/v2\\/bank_accounts\\/\\S*\\/charges$/'
        ),
        new MockRequestResponseInfo(
            // HTTP status code and body to return when this request is matched
            200,
            '{}'
        )
    ),
    ... // more mock requests
);

// create a new client with the mocking utility
$client = new EasyPostClient("some_key", Constants::TIMEOUT, Constants::API_BASE, $mockUtility);

// use the client as normal
```

###  Health Score

71

—

ExcellentBetter than 100% of packages

Maintenance84

Actively maintained with recent releases

Popularity61

Solid adoption and visibility

Community37

Small or concentrated contributor base

Maturity87

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 75.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~57 days

Recently: every ~23 days

Total

79

Last Release

82d ago

Major Versions

v4.x-dev → 5.3.02022-07-07

5.8.0 → 6.0.0-rc12022-12-15

6.9.1 → 7.0.02023-12-01

v5.x-dev → 7.2.02024-04-10

7.4.2 → 8.0.02025-04-30

PHP version history (5 changes)2.0.7PHP &gt;=5.3.0

5.0.0PHP &gt;=7.3

6.0.0-rc1PHP &gt;=7.4

7.0.0PHP &gt;=8.0

8.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/d31a025b4fb532f3f4f571de9e5f9ec090c0c8f98cde0b80e3269cdade375d1b?d=identicon)[easypost](/maintainers/easypost)

---

Top Contributors

[![Justintime50](https://avatars.githubusercontent.com/u/39606064?v=4)](https://github.com/Justintime50 "Justintime50 (474 commits)")[![sawyer](https://avatars.githubusercontent.com/u/132316?v=4)](https://github.com/sawyer "sawyer (55 commits)")[![nwithan8](https://avatars.githubusercontent.com/u/17054780?v=4)](https://github.com/nwithan8 "nwithan8 (39 commits)")[![jontsai](https://avatars.githubusercontent.com/u/422501?v=4)](https://github.com/jontsai "jontsai (10 commits)")[![victoryftw](https://avatars.githubusercontent.com/u/5474549?v=4)](https://github.com/victoryftw "victoryftw (10 commits)")[![mbeale](https://avatars.githubusercontent.com/u/1507647?v=4)](https://github.com/mbeale "mbeale (7 commits)")[![jchen293](https://avatars.githubusercontent.com/u/22759143?v=4)](https://github.com/jchen293 "jchen293 (7 commits)")[![Roguelazer](https://avatars.githubusercontent.com/u/263424?v=4)](https://github.com/Roguelazer "Roguelazer (6 commits)")[![MDrollette](https://avatars.githubusercontent.com/u/329784?v=4)](https://github.com/MDrollette "MDrollette (5 commits)")[![jstreebin](https://avatars.githubusercontent.com/u/452631?v=4)](https://github.com/jstreebin "jstreebin (2 commits)")[![hotmeteor](https://avatars.githubusercontent.com/u/378585?v=4)](https://github.com/hotmeteor "hotmeteor (2 commits)")[![browner12](https://avatars.githubusercontent.com/u/5232313?v=4)](https://github.com/browner12 "browner12 (2 commits)")[![ryannguyen16](https://avatars.githubusercontent.com/u/98357619?v=4)](https://github.com/ryannguyen16 "ryannguyen16 (2 commits)")[![wwvv3](https://avatars.githubusercontent.com/u/221153369?v=4)](https://github.com/wwvv3 "wwvv3 (1 commits)")[![Chekote](https://avatars.githubusercontent.com/u/550486?v=4)](https://github.com/Chekote "Chekote (1 commits)")[![damanic](https://avatars.githubusercontent.com/u/5227303?v=4)](https://github.com/damanic "damanic (1 commits)")[![fiendish](https://avatars.githubusercontent.com/u/201996?v=4)](https://github.com/fiendish "fiendish (1 commits)")[![gsinkin](https://avatars.githubusercontent.com/u/176146?v=4)](https://github.com/gsinkin "gsinkin (1 commits)")[![mattjanssen](https://avatars.githubusercontent.com/u/745319?v=4)](https://github.com/mattjanssen "mattjanssen (1 commits)")[![monachilada](https://avatars.githubusercontent.com/u/613183?v=4)](https://github.com/monachilada "monachilada (1 commits)")

---

Tags

apishippingeasypost

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/easypost-easypost-php/health.svg)

```
[![Health](https://phpackages.com/badges/easypost-easypost-php/health.svg)](https://phpackages.com/packages/easypost-easypost-php)
```

###  Alternatives

[gabrielbull/ups-api

PHP UPS API

4642.4M10](/packages/gabrielbull-ups-api)[gavroche/ups-api

PHP UPS API

45613.2k](/packages/gavroche-ups-api)[shipengine/shipengine

PHP library for the ShipEngine API.

172.4k](/packages/shipengine-shipengine)[michaelb/ship-station

A php wrapper for ship station's api

101.9k](/packages/michaelb-ship-station)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
