FraunhoferIOSB / FROST-Python-Client

Python Client Library for FROST.
GNU Lesser General Public License v3.0
8 stars 8 forks source link

service.things().query().top(10).list() returns all entities #17

Closed securedimensions closed 1 year ago

securedimensions commented 1 year ago

Issue

The following code returns all Thing entities and not only 10:

import frost_sta_client as fsc
import sys
import urllib.parse

url = "https://cos4cloud.demo.secure-dimensions.de/staplus/v1.1"
service = fsc.SensorThingsService(url)

things = service.things().query().top(10).list()
for thing in things:
    print("my thing: {}".format(thing.name))

What am I doing wrong?

vogljonathan commented 1 year ago

Thank you for using the FROST Python client!

The way you create a list, you get an EntityList (with .list()). Top only specifies the size of a single response. But the iterator of an EntityList runs over all entities (in your case in steps of size 10). If you don't want to use more than 10 values, you could use .entities to get a python list avoiding the entity list iterator.

things = service.things().query().top(10).list().entities

Please also note that if the top value exceeds the batch value (on the server side), you will only get a list of the length of the batch value as a response. We believe this is already covered in the readme in the section EntityList.