Skip to content

Commit

Permalink
update outdated guide on client instantiation + remove API key refere…
Browse files Browse the repository at this point in the history
…nce (#1524)
  • Loading branch information
haakonvt authored Nov 23, 2023
1 parent 4543658 commit e94205a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
5 changes: 2 additions & 3 deletions docs/source/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ Quickstart
==========
Instantiate a new client
------------------------
Use this code to instantiate a client and get your login status. CDF returns an object with
attributes that describe which project and service account your API key belongs to. The :code:`client_name`
is a user-defined string intended to give the client a unique identifier. You
Use this code to instantiate a client in order to execute API calls to Cognite Data Fusion (CDF).
The :code:`client_name` is a user-defined string intended to give the client a unique identifier. You
can provide the :code:`client_name` by passing it directly to the :ref:`ClientConfig <class_client_ClientConfig>` constructor.

The Cognite API uses OpenID Connect (OIDC) to authenticate.
Expand Down
24 changes: 19 additions & 5 deletions docs/source/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,22 @@ Settings
========
Client configuration
--------------------
You can pass configuration arguments directly to the :ref:`cognite_client:CogniteClient` constructor, for example
to configure the base url of your requests and additional headers. For a list of all configuration arguments,
see the :ref:`cognite_client:CogniteClient` class definition.
You can pass configuration arguments directly to the :ref:`ClientConfig <class_client_ClientConfig>` constructor, for example
to configure the base url of your requests or any additional headers. For a list of all configuration arguments,
see the :ref:`ClientConfig <class_client_ClientConfig>` class definition.

To initialise a ``CogniteClient``, simply pass this configuration object, (an instance of ``ClientConfig``) to it:

.. code:: python
from cognite.client import CogniteClient, ClientConfig
from cognite.client.credentials import Token
my_config = ClientConfig(
client_name="my-client",
project="myproj",
credentials=Token("verysecret"),
)
client = CogniteClient(my_config)
Global configuration
--------------------
Expand All @@ -25,13 +38,14 @@ You can set global configuration options like this:
global_config.max_connection_pool_size = 10
global_config.status_forcelist = {429, 502, 503, 504}
These must be set prior to instantiating a CogniteClient in order for them to take effect.
These must be set prior to instantiating a ``CogniteClient`` in order for them to take effect.

Concurrency and connection pooling
----------------------------------
This library does not expose API limits to the user. If your request exceeds API limits, the SDK splits your
request into chunks and performs the sub-requests in parallel. To control how many concurrent requests you send
to the API, you can either pass the :code:`max_workers` attribute when you instantiate the :ref:`cognite_client:CogniteClient` or set the :code:`max_workers` config option.
to the API, you can either pass the :code:`max_workers` attribute to :ref:`ClientConfig <class_client_ClientConfig>` before
you instantiate the :ref:`cognite_client:CogniteClient` from it, or set the global :code:`max_workers` config option.

If you are working with multiple instances of :ref:`cognite_client:CogniteClient`, all instances will share the same connection pool.
If you have several instances, you can increase the max connection pool size to reuse connections if you are performing a large amount of concurrent requests.
Expand Down
4 changes: 2 additions & 2 deletions tests/tests_unit/test_data_classes/test_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time
from contextlib import redirect_stdout
from pathlib import Path
from unittest import mock
from unittest import TestCase, mock
from unittest.mock import call

import pytest
Expand Down Expand Up @@ -127,7 +127,7 @@ def test_get_related_resources_should_not_return_duplicates(

resources = getattr(assets, method)()
expected = [r1, r2, r3]
assert expected == resources
TestCase().assertCountEqual(expected, resources) # Asserts equal, but ignores ordering

@pytest.mark.dsl
def test_to_pandas_nullable_int(self, cognite_client):
Expand Down

0 comments on commit e94205a

Please sign in to comment.