Good day, tell me. I use python sdk, to get a list of all my devices, when connecting, or rather authorization, I use my access token. When I call the method, balena.models.device.get_all (), I get a list of all devices and everything goes well. But suppose I will not have 10 or 20 devices, but 10,000 - 20,000. To get them all, I will have to unload them to my RAM, and then work with them. Which will take up a lot of memory space. Is it possible to request devices in batches somehow? Or are there any suggestions how such a problem can be solved differently?
Hi there - it’s not possible with our Python SDK to paginate the results of a query. Get_all() will do just that.
However, our API uses the OData protocol, which allows you to do $select and $filter operations as part of your queries: Overview - Balena Documentation
You could construct OData queries to control the number of results you receive at a time, and also use the $select to only receive data fields you need in your results.
What is the actual problem you are solving? Why are you finding the details for all of your devices, on a device?
Good day. I understood that for one access token, I can register several devices. And I would like to update the data about these devices, in a side thread, from the main one. I need to periodically receive information about my devices. But I am afraid that if there are too many of them, then they may not fit in memory when the Get_all () request is made.
so I want to understand how it could be done in parts.
unfortunately, as my colleague already said there is no way to have pagination for the data. Using the Python SDK you can not do anything but use the methods that we provide. The other way as my colleague said is to use OData filters via curl (docs: Resources - Balena Documentation) which can help you to divide needed data with some filter logic. Still another way could be to select only the necessary properties of the device instead of taking the whole device object, using
$select query option in the request URL (eg:
https://api.balena-cloud.com/v6/device(% 3CID% 3E)?$Select=should_be_running__release,% 20% 20device_name ). Taking only the necessary properties would allow you to keep more objects in memory. I realize that none of these is a valid solution. Data pagination is in our roadmap but, at the moment, we can’t estimate a release time.