A Python client library for GTmetrix REST API v2.0
Project description
python-gtmetrix2 is a Python client library for GTmetrix REST API v2.0 (hence 2 in the name).
Inspired by the library with a similar name.
Installation:
via pip
pip install python-gtmetrix2
file copy
This library has zero dependencies and is contained within a single file, so you can just save this file as python_gtmetrix2.py in your project directory and import it
Usage:
Simplest example:
import json
import python_gtmetrix2
api_key = "e8ddc55d93eb0e8281b255ea236dcc4f" # your API key
interface = python_gtmetrix2.Interface(api_key) # init
test = interface.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 an explanation of the above lines, dive into the docs
Testing:
Autotests are automated by Travis in clouds, so to run them you can just create a PR.
To run tests locally, you need to install pytest with httpserver and execute pytest in the root of this repository like this:
~/git/python-gtmetrix2$ pytest tests
======================== test session starts =========================
platform linux -- Python 3.9.6, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /home/lex/git/python-gtmetrix2
plugins: requests-mock-1.9.3, cov-2.12.1, httpserver-1.0.0
collected 15 items
tests/auto_test.py ............... [100%]
========================= 15 passed in 0.80s =========================
To measure coverage, install coverage and run it like this:
~/git/python-gtmetrix2$ coverage run -m pytest tests
Its output is same as above. To show actual coverage values, run:
~/git/python-gtmetrix2$ coverage report --skip-empty
Name Stmts Miss Cover
------------------------------------------------------
src/python_gtmetrix2/__init__.py 155 0 100%
tests/auto_test.py 227 0 100%
------------------------------------------------------
TOTAL 382 0 100%
To generate a coverage report in html format, run:
~/git/python-gtmetrix2$ coverage html --skip-empty
It will output nothing, but create nice HTML report in the htmlcov directory.
Tis project aims for 100% code coverage by tests, so just mark untested lines with pragma: no cover and be done with it, lol.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for python_gtmetrix2-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0401774055806fb832d10cea22f6e42fbe5ffc893c62feceee145d3aa34a7bf |
|
MD5 | 84011e1bde4ad9e4c8e11097b3dd8d7d |
|
BLAKE2b-256 | ed2696ffc8a98dc3a55fb936c1b4cbc327b09ed05f4361e3ed82631d0e99f6fc |