# psi

> PageSpeed Insights with reporting

Latest version **4.1.0** (published 2021-01-07) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install psi
pnpm add psi
yarn add psi
bun add psi
```

Provides the command `psi`.

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.1.0 |
| Published | 2021-01-07 |
| First published | 2014-06-01 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | separate (@types/psi) |
| Module format | CommonJS |
| Node | >=6 |
| Dependencies | 10 |
| Unpacked size | 24.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3097 |
| Author | Addy Osmani |
| Maintainers | sindresorhus, addyosmani, exterkamp |
| Keywords | pagespeed, insights, speed, page, website, measure, optimize, size |

## Links

- npm: https://www.npmjs.com/package/psi
- Repository: https://github.com/GoogleChromeLabs/psi
- Homepage: https://github.com/GoogleChromeLabs/psi#readme
- Issues: https://github.com/GoogleChromeLabs/psi/issues
- npm.io page: https://npm.io/package/psi

## Dependencies (10)

- [meow](https://npm.io/package/meow.md) ^6.0.1
- [pify](https://npm.io/package/pify.md) ^5.0.0
- [chalk](https://npm.io/package/chalk.md) ^3.0.0
- [sort-on](https://npm.io/package/sort-on.md) ^4.1.0
- [pretty-ms](https://npm.io/package/pretty-ms.md) ^6.0.1
- [googleapis](https://npm.io/package/googleapis.md) ^47.0.0
- [humanize-url](https://npm.io/package/humanize-url.md) ^2.1.0
- [prepend-http](https://npm.io/package/prepend-http.md) ^3.0.1
- [terminal-link](https://npm.io/package/terminal-link.md) ^2.1.1
- [update-notifier](https://npm.io/package/update-notifier.md) ^4.1.0

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 4.1.0 (latest) — 2021-01-07
- 4.0.1 — 2019-11-08
- 3.1.0 — 2018-01-22
- 3.0.0 — 2017-02-14
- 2.0.4 — 2016-06-07
- 2.0.3 — 2016-02-26
- 2.0.2 — 2015-11-16
- 2.0.0 — 2015-11-10
- 1.0.6 — 2015-02-24
- 1.0.5 — 2015-02-08
- 1.0.4 — 2015-01-19
- 1.0.3 — 2015-01-13
- 1.0.2 — 2015-01-12
- 1.0.1 — 2015-01-11
- 0.1.6 — 2014-11-28
- … 10 more at https://npm.io/package/psi/versions

## README

# psi [![Build Status](https://travis-ci.org/GoogleChromeLabs/psi.svg?branch=master)](https://travis-ci.org/GoogleChromeLabs/psi) [![NPM psi package](https://img.shields.io/npm/v/psi.svg)](https://npmjs.org/package/psi)

> PageSpeed Insights with reporting

![](screenshot.png)

Run mobile and desktop performance tests for your deployed site using [Google PageSpeed Insights v5](https://developers.google.com/speed/docs/insights/v5/about) with tidy reporting for your build process.


## Install

```
$ npm install psi
```


## Usage

<!-- TODO Update this section with v5+ information -->

```js
const psi = require('psi');

(async () => {
  // Get the PageSpeed Insights report
  const { data } = await psi('https://theverge.com');
  console.log('Speed score:', data.lighthouseResult.categories.performance.score);

  // Output a formatted report to the terminal
  await psi.output('https://theverge.com');
  console.log('Done');

  // Supply options to PSI and get back speed
  const data2 = await psi('https://theverge.com', {
    nokey: 'true',
    strategy: 'desktop'
  });
  console.log('Speed score:', data2.data.lighthouseResult.categories.performance.score);
})();
```

As of PSI 2.x, we expose both the PageSpeed Insights speed and usability scores. The latter is based on [usability rules](https://developers.google.com/speed/docs/insights/rules) that score a page based on factors like the presence of a sensible mobile [viewport](https://developers.google.com/speed/docs/insights/ConfigureViewport).

## API

### psi(url, [options])

Returns a promise for the response data from Google PageSpeed Insights.

#### url

Type: `string`

URL of the page for which the PageSpeed Insights API should generate results.

#### options

Type: `Object`

##### key

Type: `string`<br>
Default: Free tier

When using this module for a production-level build process, registering for an API key from the [Google Developer Console](https://developers.google.com/speed/docs/insights/v1/getting_started#auth) is recommended.

##### strategy

Type: `string`<br>
Default: `mobile`<br>
Values: `mobile` `desktop`

Strategy to use when analyzing the page.

##### locale

Type: `string`<br>
Default: `en_US`

Locale results should be generated in.

##### threshold

Type: `number`<br>
Default: `70`

Threshold score to pass the PageSpeed test. Useful for setting a performance budget.

##### links

Type: `boolean`<br>
Default: `false`

If passed adds links with more info about opportunities. Useful for checking documentation about opportunities.

### psi.output(url, [options])

Output the formatted report to the terminal.

Returns a promise for the response data from Google PageSpeed Insights.

`url` and `options` are the same as `psi()`.


## CLI

```
$ npm install --global psi
```

```
$ psi --help

  Usage
    $ psi <url>

  Options
    --key        Google API Key. By default the free tier is used
    --strategy   Strategy to use when analyzing the page: mobile|desktop
    --format     Output format: cli|json|tap
    --locale     Locale results should be generated in
    --threshold  Threshold score to pass the PageSpeed test

  Example
    $ psi https://addyosmani.com --strategy=mobile
```

## Common Use cases

<details>
 <summary>Getting PSI into your build process.</summary><br>

A sample [Gulp](https://github.com/addyosmani/psi-gulp-sample) project using PSI is available.

If you use Grunt, [`grunt-pagespeed`](https://github.com/jrcryer/grunt-pagespeed) is a task by James Cryer that uses PSI under the hood.

For testing local projects, we recommend using [`psi-ngrok`](https://github.com/denar90/psi-ngrok) or [`ngrok`](http://www.jamescryer.com/2014/06/12/grunt-pagespeed-and-ngrok-locally-testing/).
</details>

<details>
  <summary>Getting filmstrips</summary>

**Filmstrips** are returned by the v5 API as data uri's but the psi tool does not expose them on the cli. If you want to get **filmstrips** (or any audit details) you can require `psi` and get them from the `audits` object:

```javascript
const psi = require('psi');

(async () => {
  // Get the PageSpeed Insights report
  const {data} = await psi('https://theverge.com');
  console.log(data.lighthouseResult.audits['screenshot-thumbnails'].details.items);
})();
```

</details>

## License

Apache-2.0 - Copyright 2015 Google Inc

---
_Source: https://npm.io/package/psi · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
