Getting started


The preferred way to authenticating against the Cognite API is using OpenID Connect (OIDC). To enable this, the CogniteClient accepts a token provider function.

>>> from cognite.well_model import CogniteWellsClient
>>> def token_provider():
>>>     ...
>>> c = CogniteClient(token=token_provider)

For details on different ways of implementing the token provider, take a look at Cognite’s python-oidc-authentication examples.

If OIDC has not been enabled for your CDF project, you will want to authenticate using an API key. You can do this by setting the following environment variable

$ export COGNITE_API_KEY=<your-api-key>

or by passing the API key directly to the CogniteClient.

>>> from cognite.well_model import CogniteWellsClient
>>> c = CogniteWellsClient(api_key="<your-api-key>", client_name="<your-client-name>")


To be able to use the well data layer, the users making the request needs the wells capability. You can add this on fusion UI. The capability is called Wells.

Instantiate a new client

The entrypoint for the Well data layer is the CogniteWellsClient class. It can be instantiated using the same arguments as CogniteClient in the cognite-sdk package.

Use this code to instantiate a client. The client_name is a user-defined string intended to give the client a unique identifier. You can provide the client_name through the COGNITE_CLIENT_NAME environment variable or by passing it directly to the CogniteWellsClient constructor. All examples in this documentation assume that COGNITE_CLIENT_NAME has been set.

>>> from cognite.well_model import CogniteWellsClient
>>> wm = CogniteWellsClient(client_name="my identifier")

If you have an OIDC client_id and client_secret, the cognite wells client will refresh the token for you.

Instatiate with a known token

If you already have a token from msal or another source, you can use that token directly.

>>> import os
>>> from cognite.well_model import CogniteWellsClient
>>> token = os.getenv("COGNITE_TOKEN")
>>> wm = CogniteWellsClient(token=token)

Instantiate with OIDC using parameters

>>> import os
>>> from cognite.well_model import CogniteWellsClient
>>> wm = CogniteWellsClient(
...     client_name="my identifier",
...     project="subsurface-test",
...     base_url="",
...     token_url="",
...     token_client_id="f40c733e-8ba1-4171-8826-f89ef073ea36",
...     token_client_secret=os.getenv("COGNITE_CLIENT_SECRET"),
...     token_scopes="",
... )

Instantiate with OIDC using environment variables

export COGNITE_PROJECT="subsurface-test"
export COGNITE_CLIENT_NAME="my identifier"
export COGNITE_CLIENT_ID="f40c733e-8ba1-4171-8826-f89ef073ea36"
>>> from cognite.well_model import CogniteWellsClient
>>> wm = CogniteWellsClient()