Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for the simulators endpoint #2066

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
45 changes: 45 additions & 0 deletions cognite/client/_api/simulators/__init__.py
abdullah-cognite marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from __future__ import annotations

from typing import TYPE_CHECKING

from cognite.client._api_client import APIClient
from cognite.client._constants import DEFAULT_LIMIT_READ
from cognite.client.data_classes.simulators.simulators import Simulator, SimulatorList
from cognite.client.utils._experimental import FeaturePreviewWarning

if TYPE_CHECKING:
from cognite.client import CogniteClient
from cognite.client.config import ClientConfig


class SimulatorsAPI(APIClient):
_RESOURCE_PATH = "/simulators"

def __init__(self, config: ClientConfig, api_version: str | None, cognite_client: CogniteClient) -> None:
super().__init__(config, api_version, cognite_client)
self._warning = FeaturePreviewWarning(
api_maturity="General Availability", sdk_maturity="alpha", feature_name="Simulators"
)

def list(self, limit: int = DEFAULT_LIMIT_READ) -> SimulatorList:
"""`Filter simulators <https://developer.cognite.com/api#tag/Simulators/operation/filter_simulators_simulators_list_post>`_

List simulators

Args:
limit (int): Maximum number of results to return. Defaults to 1000. Set to -1, float(“inf”) or None to return all items.
abdullah-cognite marked this conversation as resolved.
Show resolved Hide resolved

Returns:
SimulatorList: List of simulators

Examples:

List simulators:

>>> from cognite.client import CogniteClient
>>> client = CogniteClient()
>>> res = client.simulators.list()
Comment on lines +39 to +43
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you planning to add __call__ & __iter__? I do think almost all our APIs support the "iterative" approach.


"""
self._warning.warn()
return self._list(method="POST", limit=limit, resource_cls=Simulator, list_cls=SimulatorList)
1 change: 1 addition & 0 deletions cognite/client/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class APIClient:
"geospatial/(compute|crs/byids|featuretypes/(byids|list))",
"geospatial/featuretypes/[A-Za-z][A-Za-z0-9_]{0,31}/features/(aggregate|list|byids|search|search-streaming|[A-Za-z][A-Za-z0-9_]{0,255}/rasters/[A-Za-z][A-Za-z0-9_]{0,31})",
"transformations/(filter|byids|jobs/byids|schedules/byids|query/run)",
"simulators/(list)",
abdullah-cognite marked this conversation as resolved.
Show resolved Hide resolved
"extpipes/(list|byids|runs/list)",
"workflows/.*",
"hostedextractors/.*",
Expand Down
3 changes: 3 additions & 0 deletions cognite/client/_cognite_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from cognite.client._api.raw import RawAPI
from cognite.client._api.relationships import RelationshipsAPI
from cognite.client._api.sequences import SequencesAPI
from cognite.client._api.simulators import SimulatorsAPI
from cognite.client._api.templates import TemplatesAPI
from cognite.client._api.three_d import ThreeDAPI
from cognite.client._api.time_series import TimeSeriesAPI
Expand Down Expand Up @@ -83,6 +84,8 @@ def __init__(self, config: ClientConfig | None = None) -> None:
self.documents = DocumentsAPI(self._config, self._API_VERSION, self)
self.workflows = WorkflowAPI(self._config, self._API_VERSION, self)
self.units = UnitAPI(self._config, self._API_VERSION, self)
self.simulators = SimulatorsAPI(self._config, self._API_VERSION, self)

# APIs just using base_url:
self._api_client = APIClient(self._config, api_version=None, cognite_client=self)

Expand Down
22 changes: 22 additions & 0 deletions cognite/client/data_classes/simulators/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
from __future__ import annotations

from cognite.client.data_classes.simulators.simulators import (
Simulator,
SimulatorList,
SimulatorStep,
SimulatorStepField,
SimulatorStepOption,
SimulatorUnitEntry,
SimulatorWrite,
SimulatorWriteList,
)

__all__ = [
"Simulator",
"SimulatorList",
"SimulatorStep",
"SimulatorStepField",
"SimulatorStepOption",
"SimulatorUnitEntry",
"SimulatorWrite",
"SimulatorWriteList",
]
Loading
Loading