Find Users Using the V3 SDK
This recipe uses the V3 API through the V3 Python SDK. For creating, suspending, and reactivating users, see User Management via the API.
The V3 user endpoints are beta. Set early_access="true" on the client, as in the example below,
or send the EARLY-ACCESS: true header on raw HTTP requests. See the
V3 Stability Guidelines.
SDK boilerplate
Import the V3 SDK and instantiate the client. Pass your tenant’s root URL and your API key; the SDK adds
/api/v3itself.Look a user up with user.list()
user.list()returns a pager that fetches pages as you iterate it. How you find the user depends on what you already know about them.- By username
user.list()has no username filter, so this walks the users and comparesusernameon each one.page_size=100is the maximum and keeps the number of requests down. - By display name
name_any_of_case_sensitivetakes a list of full display names as they appear in Benchling.next(iter(...), None)returns the first match, orNoneif there isn’t one. Usename_any_ofinstead for a case-insensitive match.
Look a user up by API ID
Going the other direction,
user.get()takes an API ID and returns the user, so you can read their username off it. This is a direct fetch rather than a filtered list, so there is no pager to iterate.
What changed from V2
The other filters on user.list() are id_any_of and the modified_at_* range filters. There is
no filter on email or status, so filter on those client-side.