Logging and debugging

When a script misbehaves, you want to see what the library sent and what came back. This page shows how to turn on its log messages, how to watch every request, and what to send to support.

Turn on the library's log

The library writes to a standard Python logger named thrustlab. It stays quiet unless you ask:

python
import logging

logging.basicConfig()
logging.getLogger("thrustlab").setLevel(logging.DEBUG)

At the debug level you see one line each time the library waits to retry a request, with the wait and the try number. That is all the library logs on its own. It doesn't log your requests or the answers.

Watch every request

To see each request and answer, give the library an httpx client with hooks. A hook is a function that runs on every request or answer:

python
import httpx
from thrustlab import Client

def show_request(request):
    print(request.method, request.url)

def show_response(response):
    print(response.status_code, response.headers.get("X-Request-ID"))

http = httpx.Client(
    timeout=30,
    event_hooks={"request": [show_request], "response": [show_response]},
)
client = Client(http_client=http)

Don't print the request headers. They hold your API key.

Every answer from ThrustLab also has X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset headers. A response hook can read them if you want to see how close you are to the request limit.

Find out what the library sent

Each request carries a User-Agent header that names the library, its version, your Python version and your system:

text
thrustlab-python/1.0.0 (Python/3.12.4; Windows)

Yours shows your own versions. Print thrustlab.__version__ to read the library version in code.

Send support the request id

If a call fails, the error holds a request_id. Email [email protected] with it, the call you made and the time. With the id, ThrustLab can find the exact request.

python
try:
    client.projects.retrieve("proj_...")
except Exception as error:
    print(getattr(error, "request_id", None))

See deprecation warnings

When you use an argument that is on its way out, such as flight_duration, the library raises a Python DeprecationWarning. Python hides some of these by default. To see them all, run your script with python -W default.