Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions cognite/client/_cognite_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from cognite.client.utils._auxiliary import load_resource_to_dict

if TYPE_CHECKING:
from cognite.client._sync_cognite_client import CogniteClient
from cognite.client.response import CogniteHTTPResponse


Expand Down Expand Up @@ -94,6 +95,8 @@ def __init__(self, config: ClientConfig | None = None) -> None:
# APIs just using base_url:
self._api_client = APIClient(self._config, api_version=None, cognite_client=self)

self.__sync_client: CogniteClient | None = None
Comment thread
haakonvt marked this conversation as resolved.

@property
def api_client(self) -> APIClient:
"""Returns the underlying API client used for HTTP requests.
Expand All @@ -103,6 +106,18 @@ def api_client(self) -> APIClient:
"""
return self._api_client

def get_sync_client(self) -> CogniteClient:
"""Returns a synchronous CogniteClient with the same configuration.

Returns:
CogniteClient: A sync client with the same configuration.
"""
from cognite.client._sync_cognite_client import CogniteClient

if self.__sync_client is None:
self.__sync_client = CogniteClient(self._config)
return self.__sync_client

async def get(
self, url: str, params: dict[str, Any] | None = None, headers: dict[str, Any] | None = None
) -> CogniteHTTPResponse:
Expand Down
8 changes: 8 additions & 0 deletions cognite/client/_sync_cognite_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ def api_client(self) -> APIClient:
"""
return self.__async_client._api_client

def get_async_client(self) -> AsyncCogniteClient:
"""Returns the underlying async client.

Returns:
AsyncCogniteClient: The async client instance.
"""
return self.__async_client

@classmethod
def default(
cls,
Expand Down
8 changes: 8 additions & 0 deletions scripts/sync_client_codegen/sync_client_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ class CogniteClient:
"""
return self.__async_client._api_client

def get_async_client(self) -> AsyncCogniteClient:
"""Returns the underlying async client.

Returns:
AsyncCogniteClient: The async client instance.
"""
return self.__async_client
Comment thread
haakonvt marked this conversation as resolved.

@classmethod
def default(
cls,
Expand Down
5 changes: 5 additions & 0 deletions tests/tests_integration/test_api/test_workflows.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import datetime
import time
import unittest
from collections.abc import Iterator
Expand Down Expand Up @@ -786,6 +787,10 @@ def test_trigger_list(
assert permanent_scheduled_trigger.external_id in external_ids
assert permanent_data_modeling_trigger.external_id in external_ids

@pytest.mark.skipif(
datetime.date.today() < datetime.date(2026, 6, 1),
reason="Skip until 2026-06-01",
)
Comment on lines +790 to +793
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, a Future Me Problem! 😁

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is hilarious!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

😉

def test_trigger_run_history(
self,
cognite_client: CogniteClient,
Expand Down
14 changes: 14 additions & 0 deletions tests/tests_unit/test_cognite_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,17 @@ def test_client_load(self, which_client: type[CogniteClient | AsyncCogniteClient
assert creds.token_url == TOKEN_URL
assert creds.scopes == ["https://test.com/.default", "https://test.com/.admin"]
assert client.config.debug is False

def test_sync_client_get_async_client(self, client_config_w_token_factory: ClientConfig) -> None:
sync_client = CogniteClient(client_config_w_token_factory)
async_client = sync_client.get_async_client()

assert isinstance(async_client, AsyncCogniteClient)
assert async_client.config is sync_client.config

def test_async_client_to_sync_client(self, client_config_w_token_factory: ClientConfig) -> None:
async_client = AsyncCogniteClient(client_config_w_token_factory)
sync_client = async_client.get_sync_client()

assert isinstance(sync_client, CogniteClient)
assert sync_client.config is async_client.config
Loading