Sort with order_by, slice like a list
Get the ten most recently updated workbooks — or the ten longest-dormant users — in two lines.
Why it matters
Sorting client-side has the same flaw as filtering client-side: you fetch everything to keep ten. order_by() pushes the sort to the server, and because a QuerySet slices like a list, "top N by X" becomes one chained expression. A leading minus means descending — order_by("-updated_at") is newest-first — and the sort key is validated locally exactly like filter fields are.
Write a Python script using tableauserverclient that signs in with a Personal Access Token from environment variables (TABLEAU_SERVER_URL, TABLEAU_TOKEN_NAME, TABLEAU_TOKEN_VALUE, TABLEAU_SITE_ID) and prints two top-ten lists: the ten most recently updated workbooks (order_by("-updated_at"), sliced to ten) with name and date, and the ten users who have gone longest without signing in (order_by("last_login")) with name and last login. Both sorts must happen server-side via the QuerySet API — no sorted() over a full download.
order_by() takes the same snake_case field names as filter(); prefix with - for descending. The QuerySet it returns supports indexing and slicing, so [:10] reads naturally — and stays lazy, fetching only what the slice needs.
Filter and sort compose on one QuerySet, which is the whole point of the idiom: one expression, one precise question, one server-shaped answer.
Got what you came for? Mark the stop and the line fills in beneath you.