PHPackages                             developmint/npm-stats-api - 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. developmint/npm-stats-api

ActiveLibrary[API Development](/categories/api)

developmint/npm-stats-api
=========================

Fetch stats for your NPM packages

v2.0.0(5y ago)166.6k1[1 PRs](https://github.com/Developmint/npm-stats-api/pulls)1MITPHPPHP ^7.2CI failing

Since Oct 11Pushed 5y ago1 watchersCompare

[ Source](https://github.com/Developmint/npm-stats-api)[ Packagist](https://packagist.org/packages/developmint/npm-stats-api)[ Docs](https://github.com/developmint/npm-stats-api)[ RSS](/packages/developmint-npm-stats-api/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependencies (2)Versions (6)Used By (1)

Fetch stats for your NPM packages
=================================

[](#fetch-stats-for-your-npm-packages)

[![Latest Version on Packagist](https://camo.githubusercontent.com/529ffcfb501700bf53fae7b7689d5adc1e1b6fced3030edcbd2339d6a6437c3d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646576656c6f706d696e742f6e706d2d73746174732d6170692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/developmint/npm-stats-api)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/75d4669a7d1b4d18904d15fe718e1bea02da6331e43efb5217478242cb7a6d9e/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f446576656c6f706d696e742f6e706d2d73746174732d6170692f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/Developmint/npm-stats-api)[![Quality Score](https://camo.githubusercontent.com/2b3d2c16b1adeca0f81d7762b521729574e1f55cb0bc8bdb757b1f1db9a4b1c2/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f646576656c6f706d696e742f6e706d2d73746174732d6170692e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/developmint/npm-stats-api)[![Total Downloads](https://camo.githubusercontent.com/4e4702d2ba6e32d8021e1fe774cb2d256c90036bc85bb3a064dc283c62046206/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646576656c6f706d696e742f6e706d2d73746174732d6170692e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/developmint/npm-stats-api)

This package makes it easy to retrieve stats for packages hosted on [npmjs.com](https://www.npmjs.com/)

PS: It's heavily inspired by the [packagist-api package](https://github.com/spatie/packagist-api) made from Spatie

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require developmint/npm-stats-api
```

Usage
-----

[](#usage)

You must pass a Guzzle client to the constructor of `Developmint\NpmStats\NpmStats`.

```
$client = new \GuzzleHttp\Client();

$npmStats = new \Developmint\NpmStats\NpmStats($client);
```

### Get stats for a package of your choice

[](#get-stats-for-a-package-of-your-choice)

```
$npmStats->getStats('jquery');
```

### Get stats with a period of your choice

[](#get-stats-with-a-period-of-your-choice)

Use a constant provided by the NpmStats class to get stats for the last day, week, month, year or in total.

```
$npmStats->getStats('jquery', NpmStats::LAST_DAY);
```

You can also pass in specific dates

```
$npmStats->getStats('jquery', '2017-01-01');
```

Or even ranges

```
$npmStats->getStats('jquery', '2014-02-07:2014-02-14');
```

The output will be already decoded from json:

```
array(4) {
  ["downloads"]=>
  int(198672)
  ["start"]=>
  string(10) "2017-10-10"
  ["end"]=>
  string(10) "2017-10-10"
  ["package"]=>
  string(6) "jquery"
}
```

### Get stats with a period of your choice as range

[](#get-stats-with-a-period-of-your-choice-as-range)

You can also get the stats as a *range*, means the downloads split up per day:

```
$npmStats->getStats('jquery', NpmStats::LAST_WEEK, true);
```

And this would be the result of that call:

```
array(4) {
  ["start"]=>
  string(10) "2017-10-04"
  ["end"]=>
  string(10) "2017-10-10"
  ["package"]=>
  string(6) "jquery"
  ["downloads"]=>
  array(7) {
    [0]=>
    array(2) {
      ["downloads"]=>
      int(200678)
      ["day"]=>
      string(10) "2017-10-04"
    }
    [1]=>
    array(2) {
      ["downloads"]=>
      int(195593)
      ["day"]=>
      string(10) "2017-10-05"
    }
    [2]=>
    array(2) {
      ["downloads"]=>
      int(172132)
      ["day"]=>
      string(10) "2017-10-06"
    }
    [3]=>
    array(2) {
      ["downloads"]=>
      int(51068)
      ["day"]=>
      string(10) "2017-10-07"
    }
    [4]=>
    array(2) {
      ["downloads"]=>
      int(46892)
      ["day"]=>
      string(10) "2017-10-08"
    }
    [5]=>
    array(2) {
      ["downloads"]=>
      int(171920)
      ["day"]=>
      string(10) "2017-10-09"
    }
    [6]=>
    array(2) {
      ["downloads"]=>
      int(198672)
      ["day"]=>
      string(10) "2017-10-10"
    }
  }
}
```

### Get bulk stats

[](#get-bulk-stats)

Of course you can retrieve up to 128 packages as a bulk query. Simply separate them with a command and you are good to go.

```
$npmStats->getStats('vue,express', NpmStats::LAST_WEEK);
```

But beware! This only works in point mode, not in range mode.

```
$npmStats->getStats('vue,express', NpmStats::LAST_WEEK, true);
//Won't work
```

Anyway, the output will look similar to the normal point mode output:

```
array(2) {
  ["vue"]=>
  array(4) {
    ["downloads"]=>
    int(3980980980098089080980983)
    ["package"]=>
    string(5) "vue"
    ["start"]=>
    string(10) "2017-10-10"
    ["end"]=>
    string(10) "2017-10-10"
  }
  ["express"]=>
  array(4) {
    ["downloads"]=>
    int(818264)
    ["package"]=>
    string(7) "express"
    ["start"]=>
    string(10) "2017-10-10"
    ["end"]=>
    string(10) "2017-10-10"
  }
}
```

More in-depth info about the NPM stats API
------------------------------------------

[](#more-in-depth-info-about-the-npm-stats-api)

You can find a detailed explanation about how the stats API of NPM works in this [repository README file](https://github.com/npm/registry/blob/master/docs/download-counts.md)

Limits of the API
-----------------

[](#limits-of-the-api)

The official limits are:

- Bulk queries: 128 packages at a time and at most 365 days of data
- All other queries: limited to at most 18 months of data
- Earliest date available: January 10, 2015

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Alexander Lichter](https://github.com/manniL)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 90.9% 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 ~266 days

Total

5

Last Release

2073d ago

Major Versions

v1.0.3 → v2.0.02020-09-10

PHP version history (2 changes)v1.0.0PHP ^7.0

v2.0.0PHP ^7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/7c0c843e7f5459f98b8f51485b7cc461a41feebb1e918c4024ddc8cc88df8012?d=identicon)[developmint](/maintainers/developmint)

---

Top Contributors

[![TheAlexLichter](https://avatars.githubusercontent.com/u/640208?v=4)](https://github.com/TheAlexLichter "TheAlexLichter (10 commits)")[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (1 commits)")

---

Tags

fetch-statsnpmstatsstats-apiapistatsnpmdevelopmint

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/developmint-npm-stats-api/health.svg)

```
[![Health](https://phpackages.com/badges/developmint-npm-stats-api/health.svg)](https://phpackages.com/packages/developmint-npm-stats-api)
```

###  Alternatives

[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.6M74](/packages/openai-php-laravel)[mailchimp/transactional

458.9M16](/packages/mailchimp-transactional)[get-stream/stream-chat

A PHP client for Stream Chat (https://getstream.io/chat/)

301.8M2](/packages/get-stream-stream-chat)[convertkit/convertkitapi

Kit PHP SDK for the Kit API

2167.1k1](/packages/convertkit-convertkitapi)

PHPackages © 2026

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