Skip to main content

This library is a wrapper for the TestMo REST API

Project description

TestMo-API

TestMo API wrapper

TestMo REST API Link

Using the ErrorHandling class

The project includes a simple HTTP error handler that raises requests.exceptions.HTTPError for non-success HTTP responses and enriches the message with details from the server response (if available).

Basic usage with requests:

import requests
from pyTestMoApi._utils._errors import ErrorHandling

# Example GET request
res = requests.get("https://example.testmo.net/api/v1/projects", headers={"Authorization": "Bearer <TOKEN>"}, timeout=15)

# Will do nothing if status_code < 300; otherwise raises HTTPError with details
ErrorHandling(res.status_code, response=res).handler()

# If we reach here, the request succeeded
print(res.json())

Catching errors:

import requests
from requests.exceptions import HTTPError
from pyTestMoApi._utils._errors import ErrorHandling

try:
    res = requests.get("https://example.testmo.net/api/v1/projects", headers={"Authorization": "Bearer <TOKEN>"}, timeout=15)
    ErrorHandling(res.status_code, response=res).handler()
except HTTPError as e:
    # e will include status code, a friendly message for known errors (401/403/404/405/422/429),
    # any message/detail sent by the server, and a link to Testmo docs.
    print(f"Request failed: {e}")

Notes:

  • For known status codes (401, 403, 404, 405, 422, 429), the handler prints a friendly message and includes details such as JSON message/detail or Retry-After headers when rate-limited.
  • For any other >= 300 status code, the handler raises an HTTPError with an "Unknown error" message and includes any details it can parse from the response.
  • If you don’t pass the response object, the error will still be raised for non-success codes, just without extra parsed details.

Using together with ApiClient

The included ApiClient wraps GET/POST requests to the Testmo API. After each request it calls the error handler. Example:

from pyTestMoApi.api_client import ApiClient

client = ApiClient(token="<TOKEN>", instance="example")  # or set TESTMO_TOKEN and TESTMO_INSTANCE env vars

# GET projects
res = client.api_get("/projects")
print(res.json())

# POST example
payload = {"name": "My Project"}
res = client.api_post("/projects", json=payload)
print(res.json())
uv sync           # to create/update the environment
uv sync --all-extras --group dev  # to create/update the environment with extras
uv build          # to build the package
uv pip install .  # to install the local package

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

testmoapiclient-0.1.1.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

testmoapiclient-0.1.1-py3-none-any.whl (29.1 kB view details)

Uploaded Python 3

File details

Details for the file testmoapiclient-0.1.1.tar.gz.

File metadata

  • Download URL: testmoapiclient-0.1.1.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for testmoapiclient-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4baabb43dee2f620c25a7199b2ca696ab894bca6737e6da7e8dc23ebad2ce578
MD5 46a778bb67ae32cfd30c3858c24a99cd
BLAKE2b-256 2461747bb2f92a098ff605d4eeef857cbeb5e5903d792d21757cd53cc0fb79ae

See more details on using hashes here.

File details

Details for the file testmoapiclient-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for testmoapiclient-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7632fd8824af9fa04d521bbc188cbcbc576a3d4ef8b5f70943c0994dd900d575
MD5 b0afed5e371a140c82ff438f81331abc
BLAKE2b-256 601e401539be97c7586bb2ebda60624c7a3b02d4a31fab120c3d25e60423a955

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page