Convert SDK Objects to JSON
This example reads every plate in a tenant with the V3 Python SDK and converts the resulting SDK objects to JSON. Plates are just the example; the same pattern works for any object the SDK returns, because every V3 SDK model is a pydantic model.
The V3 plate list endpoint is 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.
Initialize the environment
Import the SDK and
json, then create a Benchling client. Pass your tenant’s root URL and your API key; the SDK adds/api/v3itself.List plates
plate.list()requests the first page straight away and returns a pager that fetches the rest as you go.Loop through the results
iter_pages()walks each page of results, and the inner loop walks the individual plates in that page’sitems(50 per page by default, up to 100 withpage_size). To skip the paging detail, iterateplatesdirectly instead. See Pagination.Convert each plate
dict(mode="json")turns an SDK model into a plain dictionary thatjsoncan write: camelCase keys, as in the API response, and only the fields the API returned. Collecting them inserialized_platesmakes the whole set easy to serialize at the end, but this is the point where you would instead reshape the data into whatever your use case needs.Write the data to a file
The response tab shows the shape of the output. In V3,
wellsis a link rather than the well contents; callbenchling.plate.list_wells()with the plate’s ID to read them.
Other ways to serialize a model
The V3 SDK models are pydantic v2 models with snake_case attribute names and camelCase aliases, so the output depends on which method you call:
mode="json" converts values such as datetimes to strings. Without it, a model that holds a
datetime produces a dictionary that json.dumps() can’t write.