This library is a wrapper for the TestMo REST API
Project description
TestMo-API
TestMo API wrapper
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
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file testmoapiclient-0.1.2.tar.gz.
File metadata
- Download URL: testmoapiclient-0.1.2.tar.gz
- Upload date:
- Size: 18.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52530cc8c52609514f8eb6ce7e746742ff6af026dfb760e246ca9baaaa14b5e4
|
|
| MD5 |
df2c9d8031947e55388faaf1e5ee1106
|
|
| BLAKE2b-256 |
18844678081c8d8be060ea54708faef264b52a05d117911ae51aee5121387432
|
File details
Details for the file testmoapiclient-0.1.2-py3-none-any.whl.
File metadata
- Download URL: testmoapiclient-0.1.2-py3-none-any.whl
- Upload date:
- Size: 30.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
807f99de691fa7580023aa01a292948526487b49b4ff1b908a524dc93afacc0f
|
|
| MD5 |
6fbab4b24c8b5db7ca782c63650c44f8
|
|
| BLAKE2b-256 |
62110bd255ab5ff240b21d4f652545a332801afc4db59780ff6f9ea3688e494e
|