Warning

As long as major version of this library is 0 (i.e. library has version 0.x.y), API is not guaranteed to be compatible between versions. When you start using this library, please let the developer know about - I will bump the major version to 1, and usuall semver guatantees regarding version compatibility will be applied.

python-gtmetrix2

python-gtmetrix2 is a Python client library for GTmetrix REST API v2.0 (hence 2 in the name).

Build Status codecov Code style: black Documentation Status License: MIT

PyPI - Latest Version PyPI - Python Version PyPI - Downloads Monthly PyPI - Downloads Daily

Inspired by the library with a similar name.

Installation:

via pip

pip install python-gtmetrix2

manual

  • Clone or download and extract the repository

  • Copy the src/python-gtmetrix2 directory to your project directory

Usage:

Simplest example:

import json
import python_gtmetrix2

api_key = "e8ddc55d93eb0e8281b255ea236dcc4f"    # your API key
url = "http://example.com"                      # URL to test

account = python_gtmetrix2.Account(api_key)     # init
test = account.start_test(url)                  # start test
test.fetch(wait_for_completion=True)            # wait for it to finish
report = test.getreport()                       # get test result

print(json.dumps(report, indent=2))             # do something useful with it

For a wordy introduction into this library, please see next chapter. For more advanced examples, see the examples section. For a more technical explanation, dive into API reference.