Preflight Checklist
OpenMeter Version
1.0.0b227
Expected Behavior
Even though the SDK provides a way to access the V2 events api on a per-page basis, the iterators on top of the underlying request completely mask the cursors returned by the API.
While this is great to iterate in a friendly manner in Python without having to worry about underlying implementation, it robs the user of the ability to paginate and return data as is.
Since the SDK allows to specify a cursor value, I would expect to be able to read the nextCursor value myself.
As a result, I have to resort to digging into private attributes and the http response, which could break at any time.
Here's an example of what I ended up doing:
async with get_client() as client:
events = client.events_v2.list(
cursor=query.cursor,
limit=query.limit)
events_list = []
iterator = events.by_page()
first_page = await anext(iterator)
next_cursor = iterator._response.http_response.json().get("nextCursor") # type: ignore
async for event in first_page:
events_list.append(event.as_dict())
if query.limit and len(events_list) < query.limit:
next_cursor = None
return {"items": events_list, "nextCursor": next_cursor}
Actual Behavior
nextCursor is not exposed in the events iterator in a public way.
Steps To Reproduce
- in a Python 3.12 environment
- with the SDK version mentioned above
- Given a valid API key and client
- Run the code provided above.
Additional Information
No response
Preflight Checklist
OpenMeter Version
1.0.0b227
Expected Behavior
Even though the SDK provides a way to access the V2 events api on a per-page basis, the iterators on top of the underlying request completely mask the cursors returned by the API.
While this is great to iterate in a friendly manner in Python without having to worry about underlying implementation, it robs the user of the ability to paginate and return data as is.
Since the SDK allows to specify a cursor value, I would expect to be able to read the
nextCursorvalue myself.As a result, I have to resort to digging into private attributes and the http response, which could break at any time.
Here's an example of what I ended up doing:
Actual Behavior
nextCursoris not exposed in the events iterator in a public way.Steps To Reproduce
Additional Information
No response