Python
Python client options for the TagManifest API. Manual requests wrapper and generated client via openapi-generator-cli.
There is no officially published PyPI package for TagManifest today. This page documents two approaches that work against the live API: a minimal requests-based wrapper suitable for most use cases, and a generated Python client from the OpenAPI spec for teams that want full model coverage.
Beta — generated client not officially published yet. The OpenAPI spec at /openapi.json is stable, but the generated PyPI package is not in the registry. Use the manual wrapper for production, or generate a local client from the spec.
Status
The TagManifest REST API is stable and versioned at the path level. All six endpoints work with any HTTP client library. An officially maintained PyPI package is planned; until then, the approaches below cover the full API surface.
Manual requests wrapper
The wrapper below uses the requests library and covers the scan and rule endpoints: scan_url, scan_container, evaluate_rule, list_rules and get_rule. Install requests with pip install requests if it is not already in your environment.
import os
import requests
BASE = "https://developer.tagmanifest.com/v1"
def _headers():
return {"Authorization": f"Bearer {os.environ['TM_API_KEY']}"}
def _post(path, payload):
resp = requests.post(
f"{BASE}{path}",
json={k: v for k, v in payload.items() if v is not None},
headers=_headers(),
timeout=30,
)
resp.raise_for_status()
return resp.json()
def _get(path, params=None):
resp = requests.get(
f"{BASE}{path}",
params={k: v for k, v in (params or {}).items() if v is not None},
headers=_headers(),
timeout=30,
)
resp.raise_for_status()
return resp.json()
def scan_url(url=None, gtm_id=None, category=None, tier=None, top_n=None, include_evidence=False):
return _post("/scan-url", locals())
def scan_container(data, category=None, tier=None, top_n=None, include_evidence=False):
return _post("/scan", {"data": data, "category": category,
"tier": tier, "top_n": top_n,
"include_evidence": include_evidence})
def evaluate_rule(rule_id, url=None, gtm_id=None, data=None):
return _post("/evaluate-rule", {"rule_id": rule_id, "url": url,
"gtm_id": gtm_id, "data": data})
def list_rules(category=None, tier=None, status=None, limit=None):
return _get("/rules", {"category": category, "tier": tier,
"status": status, "limit": limit})
def get_rule(rule_id):
return _get("/rules-detail", {"rule_id": rule_id})
The _post and _get helpers strip None values from payloads so optional parameters do not appear as explicit nulls in request bodies.
GET /rules accepts four query parameters: category, tier, status and limit. Any other parameter, such as layer, is refused with a 400. The same is true of unknown fields in the POST bodies. Paths are written without a trailing slash, as on the endpoint pages.
Generated client
The OpenAPI spec is available at https://developer.tagmanifest.com/openapi.json. Use openapi-generator-cli to produce a Python client with typed models:
openapi-generator-cli generate \
-i https://developer.tagmanifest.com/openapi.json \
-g python \
-o ./tagmanifest-client-py \
--additional-properties=packageName=tagmanifest_client
Install the generated package into your environment:
cd tagmanifest-client-py
pip install -e .
Then import and configure:
import os
import tagmanifest_client
from tagmanifest_client.api.default_api import DefaultApi
from tagmanifest_client.configuration import Configuration
configuration = Configuration(
host="https://developer.tagmanifest.com/v1",
access_token=os.environ["TM_API_KEY"],
)
with tagmanifest_client.ApiClient(configuration) as client:
api = DefaultApi(client)
result = api.scan_url({"url": "https://example.com", "top_n": 25})
print(result.health_score.score)
Method names come from the operationId values in the spec: scan_url, scan_container, evaluate_rule, list_rules, get_rule. The exact class, method and parameter names depend on the generator version. Check the README the generator writes into the output folder.
Regenerate the client whenever you pull a new version of the spec. The spec is hand-authored from the live function source and updated when endpoints change.
Error handling
The requests library raises requests.exceptions.HTTPError when raise_for_status() encounters a non-2xx response. Read the response body to get the TagManifest error message:
import requests
try:
result = scan_url(url="https://example.com")
except requests.exceptions.HTTPError as e:
body = e.response.json()
print(f"API error {e.response.status_code}: {body.get('error')}")
if e.response.status_code == 429:
reset_at = body.get("reset_at")
print(f"Rate limit resets at {reset_at}")
The errors you are most likely to encounter:
| Status | Cause |
|---|---|
| 400 | Missing, malformed or unknown request field — check parameter names and types. A misspelt field is refused, not ignored. |
| 401 | Invalid or missing API key — check TM_API_KEY. |
| 429 | Daily rate limit exceeded — read reset_at from the body and back off. |
| 502 | The target URL or GTM CDN was unreachable — retry with backoff. |
See Errors for the full list.
Rate-limit headers
Responses to requests that were counted include X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset. That covers 200 responses, the 429, and errors such as 400, 404 and 502. The headers are absent on 401, 403, 405 and 503 responses, so check that they exist before reading them:
import requests
resp = requests.post(
f"{BASE}/scan-url",
json={"url": "https://example.com"},
headers=_headers(),
timeout=30,
)
remaining = resp.headers.get("X-RateLimit-Remaining")
reset_at = resp.headers.get("X-RateLimit-Reset")
if remaining is not None and int(remaining) < 5:
print(f"Approaching scan_url limit. Resets at {reset_at}")
resp.raise_for_status()
result = resp.json()
When the limit is reached, wait until the reset time. There are no paid plans and no way to raise a limit. See Rate limits for daily caps by tool.
Examples
import os
import requests
BASE = "https://developer.tagmanifest.com/v1"
def scan_url(url=None, gtm_id=None, top_n=25, **kwargs):
params = {k: v for k, v in
dict(url=url, gtm_id=gtm_id, top_n=top_n, **kwargs).items()
if v is not None}
resp = requests.post(
f"{BASE}/scan-url",
json=params,
headers={"Authorization": f"Bearer {os.environ['TM_API_KEY']}"},
timeout=30,
)
resp.raise_for_status()
return resp.json()
result = scan_url(url="https://example.com", top_n=25)
print(result["health_score"]["score"])
openapi-generator-cli generate \
-i https://developer.tagmanifest.com/openapi.json \
-g python \
-o ./tagmanifest-client-py \
--additional-properties=packageName=tagmanifest_client
cd tagmanifest-client-py
pip install -e .