Giter VIP home page Giter VIP logo

pypsi's Introduction

PyPSI

CLI ๐Ÿ–ฅ + API for Google PageSpeed Insights

PythonPSI PyPI - Downloads

PyPSI

PageSpeed Insights (PSI) reports on the performance of a page on both mobile and desktop devices, and provides suggestions on how that page may be improved.

PSI provides both lab and field data about a page. Lab data is useful for debugging performance issues, as it is collected in a controlled environment. However, it may not capture real-world bottlenecks. Field data is useful for capturing true, real-world user experience - but has a more limited set of metrics.

PyPSI uses PageSpeed Insights API v5

Installation

pip install PythonPSI

Usage

Google seems to have made it mandatory to use an API key, otherwise you may reach service quota limits too soon. Get one from here.

psi <SITE_URL> <OPTION1> <OPTION2> ...

Example:

$ psi developers.google.com --category seo --stratergy desktop --locale en

    {
    "captchaResult": "CAPTCHA_NOT_NEEDED",
    "kind": "pagespeedonline#result",
    "id": "https://developers.google.com/",
    "loadingExperience": {
        ...
    },
    "originLoadingExperience": {
        ...
    },
    "lighthouseResult": {
        ...
    },
    "analysisUTCTimestamp": {
        ...
    }

CLI

$ psi --help

    Usage: psi [OPTIONS] URL

    Options:
    --api_key TEXT        Required to use the API in an automated way and make
                            multiple requests per second

    --category TEXT       A Lighthouse category to run; if none are given, only
                            Performance category will be run

    --metrics TEXT        Returns metrics of a particular field in response
                            object

    --locale TEXT         The locale used to localize formatted results
    --stratergy TEXT      The analysis stratergy (desktop or mobile) to use, and
                            desktop is the default

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

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

    --utm_campaign TEXT   Campaign name for analytics.
    --utm_source TEXT     Campaign source for analytics.
    --captcha_token TEXT  The captcha token passed when filling out a captcha.
    --help                Show this message and exit.

API Usage

from PythonPSI.api import PSI

PSI('google.com', category='seo', locale='en', stratergy='desktop')
# Returns JSON output
  • PSI - Required arguments: 1, Optional arguments: 9

    • URL:
      • Required
      • Default: None
    • api_key:
      • Optional
      • Default: None
    • category:
      • Optional
      • Default: performance
      • Options: accessibility, best_practices, performance, pwa, seo
    • metrics:
      • Optional
      • Default: None
      • Options: kind, captchaResult, id, loadingExperience, originLoadingExperience, analysisUTCTimestamp, lighthouseResult, version
    • locale:
      • Optional
      • Default: en
    • stratergy:
      • Optional
      • Default: desktop
      • Options: desktop, mobile
    • threshold:
      • Optional
      • Default: None
      • Options: INT 0-100
    • links:
      • Optional
      • Default: false
      • Options: true, false
    • utm_campaign:
      • optional
      • Default: None
    • utm_source:
      • Optional
      • Default: None
    • captcha_token:
      • Optional
      • Default: None

pypsi's People

Contributors

fireping32 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

pypsi's Issues

stratergy='mobile' is returning desktop results

i execute this:
mobile = PSI(url=URL, category='performance', locale='en', stratergy='mobile', api_key=API_KEY)

and in the json i see that i get the desktop result:
{'emulatedFormFactor': 'desktop', 'formFactor': 'desktop', 'locale': 'en', 'onlyCategories': ['performance'], 'channel': 'lr'}

I also verified the numbers, i sloud have scored much less in the mobile test

Setup Error Reporting

The current version does not give that much information when a request fails. The API does give much more information in the 'message' attribute.

It would be nice if that error message is available in the exception.

Ref: #2

More details if request fails?

Hi,

The current version does not give that much information when a request fails. The only I get with str(ex) is 'lighthouseResult'.
The API does give much more information in the 'message' attribute.

It would be nice if that error message is available in the exception. Is that possible?

{ "error": { "code": 500, "message": "Lighthouse returned error: FAILED_DOCUMENT_REQUEST. Lighthouse was unable to reliably load the page you requested. Make sure you are testing the correct URL and that the server is properly responding to all requests. (Details: net::ERR_CONNECTION_FAILED)", "errors": [ { "message": "Lighthouse returned error: FAILED_DOCUMENT_REQUEST. Lighthouse was unable to reliably load the page you requested. Make sure you are testing the correct URL and that the server is properly responding to all requests. (Details: net::ERR_CONNECTION_FAILED)", "domain": "lighthouse", "reason": "lighthouseError" } ] } }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.