Skip to Content
Language guide

Call Supervisor from Python

Use the Python standard library to authenticate, send JSON, and parse the response.

Language guide
01

Standard library client

The example uses urllib.request so it runs without a third party package. Load SUPERVISOR_API_KEY from the process environment and keep the script outside client distributed code.

import json
import os
import urllib.request
url = "https://api.trysupervisor.com/workspaces/user/me"
request = urllib.request.Request(url, method="GET")
request.add_header("Authorization", f"Bearer {os.environ['SUPERVISOR_API_KEY']}")
request.add_header("Content-Type", "application/json")
with urllib.request.urlopen(request) as response:
result = json.load(response)
print(json.dumps(result, indent=2))
02

Failure handling

Catch urllib.error.HTTPError to inspect the status and response body. Treat validation errors as final until the request changes, and retry only transient responses with a bounded delay.