Getting started

Authenticate

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>")

Authorization

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="https://api.cognitedata.com",
...     token_url="https://login.microsoftonline.com/6f180895-9118-4835-9b3f-94e11d2f57ab/oauth2/v2.0/token",
...     token_client_id="f40c733e-8ba1-4171-8826-f89ef073ea36",
...     token_client_secret=os.getenv("COGNITE_CLIENT_SECRET"),
...     token_scopes="https://api.cognitedata.com/.default",
... )

Instantiate with OIDC using environment variables

export COGNITE_PROJECT="subsurface-test"
export COGNITE_BASE_URL="https://api.cognitedata.com"
export COGNITE_CLIENT_NAME="my identifier"
export COGNITE_CLIENT_ID="f40c733e-8ba1-4171-8826-f89ef073ea36"
export COGNITE_CLIENT_SECRET="A secret"
export COGNITE_TOKEN_URL="https://login.microsoftonline.com/6f180895-9118-4835-9b3f-94e11d2f57ab/oauth2/v2.0/token"
export COGNITE_TOKEN_SCOPES="https://api.cognitedata.com/.default"
>>> from cognite.well_model import CogniteWellsClient
>>> wm = CogniteWellsClient()