feat(streams): Streams API#2534
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2534 +/- ##
==========================================
+ Coverage 92.99% 93.02% +0.02%
==========================================
Files 482 486 +4
Lines 48995 49208 +213
==========================================
+ Hits 45564 45775 +211
- Misses 3431 3433 +2
🚀 New features to boost your workflow:
|
This comment was marked as outdated.
This comment was marked as outdated.
c0ac1ca to
b83f313
Compare
This comment was marked as resolved.
This comment was marked as resolved.
haakonvt
left a comment
There was a problem hiding this comment.
Part 1 of review: cognite/client/_api/streams/__init__.py
1902069 to
02d53d4
Compare
This comment was marked as resolved.
This comment was marked as resolved.
29a0184 to
6829245
Compare
c2d5bad to
3225b62
Compare
The StreamsAPI needs to chunk items one at a time for create and delete operations, similar to other APIs like AgentsAPI. This ensures each stream is processed in a separate API request rather than being bundled together. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Remove unused imports that were causing lint failures (F401 errors): - asyncio, Coroutine, Iterator (not used) - Any, Literal, overload, TYPE_CHECKING (not used) - APIClient (not used) - SyncIterator, run_sync (not used) - _get_event_loop_executor (not used) - pandas, ClientConfig (not used) Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
… PR 2534 structure This refactors the Streams and Records API to be part of the data_modeling module rather than a separate top-level streams module, matching the structure of PR #2534. Changes: - Move StreamsAPI from _api/streams to _api/data_modeling/streams - Move StreamsRecordsAPI from _api/streams/records to _api/data_modeling/records - Move stream data classes to data_modeling/streams.py (includes record classes) - Integrate records API into StreamsAPI via self.records attribute - Remove direct self.streams attribute from AsyncCogniteClient - Streams now accessed via client.data_modeling.streams - Generate sync API wrappers for new locations - Update all imports and exports Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
haakonvt
left a comment
There was a problem hiding this comment.
2 more comments, but looking great 🤩
| res = await self._get(url_path=self._RESOURCE_PATH, semaphore=self._get_semaphore("read")) | ||
| return StreamList._load(res.json()["items"]) |
There was a problem hiding this comment.
I think that should be fine:
return await self._list("GET", list_cls=StreamList, resource_cls=Stream)|
|
||
| @classmethod | ||
| def _parse_settings(cls, raw: dict[str, Any]) -> StreamTemplateWriteSettings | dict[str, Any]: | ||
| if set(raw.keys()) == {"template"} and isinstance(raw["template"], dict) and "name" in raw["template"]: |
There was a problem hiding this comment.
Should the presence of other keys besides "template" prevent this from triggering? If no, then consider structural pattern matching also:
match raw:
case {"template": {"name": str()}}:
return StreamTemplateWriteSettings._load(raw)
case _:
return rawThere was a problem hiding this comment.
No, this is currently required. and going forward we want users to be cognizant on what template is configured as it directly impacts their usecase. So for now I think this is fine.
dug into our code, future plans, etc. I don't see a reason to support this and I think this came about from AI slop. my fault :sadpanda:
manually verified that extra uri args are ignored for the endpoint. eg. limit parameter that is injected by default
since we now use _list we need to update the regex to allow injected uri args like limit
Summary
Add streams api to sdk.
Example
This PR does not add the Records API (#2535).
closes #2519
closes #2246