marqo-ai / py-marqo

Python client for Marqo
https://marqo.pages.dev/
Apache License 2.0
30 stars 5 forks source link

Align `get_indexes()` with API spec #114

Open OwenPendrighElliott opened 1 year ago

OwenPendrighElliott commented 1 year ago

e.g. the python client returns

{'results': [<marqo.index.Index object at 0x103f65090>]}

Where the REST API returns

{'results': [{"index-name", "my-first-index"}]}

e.g.

>>> indexes = mq.get_indexes()['results']
>>> for index in indexes:
...    print(index.get_stats())
>>>

However this usage pattern is never documented anywhere or used in any examples as far as I can see. It only appears in one of the tests for the get_indexes() method.

An alternative would be to add __getitem__ and __repr__ to the index object to retain both the existing functionality and let users treat it like a dict. e.g.

>>> indexes = mq.get_indexes()['results']
>>> for index in indexes:
...    print(index.get_stats())
>>> print(indexes)
[Index(config=<marqo.config.Config object at 0x10382f610>, http=<marqo._httprequests.HttpRequests object at 0x102682b10>, index_name='my-first-index', created_at=None, updated_at=None)]
>>> indexes[0]['index_name']
'my-first-index'
OwenPendrighElliott commented 1 year ago

@pandu-k what are your thoughts on this? I think we discussed it about 2 months ago but I never got around to taking in further.