Skip to main content
Python

Prepare the request

The script reads your API token from the LUMOS_API_TOKEN environment variable, so the token never appears in the code. Create a token on the API Tokens page. For details, see Authentication. The script uses Python 3 and the requests library (pip install requests).
get() sends each request and handles one failure itself. When a response is a 429, meaning you’re over the rate limit, it waits the number of seconds in the Retry-After header, then tries again. Any other error raises, so a bad token stops the script with a 401 instead of printing nothing. List Apps returns the apps the token’s user can see in Lumos. If that user can’t see apps at all, it returns 403.

Read every page

A response holds one page of apps and a next_page_token. The loop sends that page token as page_token in the next call, and stops when next_page_token is missing or null. A page with fewer than page_size apps doesn’t mean it was the last page. Pagination explains why. A page holds at most 250 apps, whatever page_size you send. Lumos lowers larger values to 250 instead of rejecting them. Larger pages use fewer requests against your rate limit.

Read each app

The loop prints the fields that identify an app. The App object describes the rest. Read fields with app.get() rather than app[...]. An app omits fields that have no value, as Absent and null fields describes, so a key such as instance_id can be missing rather than null. id is always there. To narrow the list, add filters to params and keep them on every page: