Configuration

The Descartes Labs Python Client can be configured to operate in several modes. The main distinction is whether the client is configured to operate with the Descartes Labs Google-based platform (“gcp”) or the AWS-based Enterprise Accelerator platform (“aws”). For most users, the selection will be performed automatically based on the properties of the authenticated user, determined at login time:

descarteslabs auth login

If the user is authorized for the AWS Enterprise Accelerator platform the client will be automatically configured as such, otherwise the client will be automatically configured for the Google-based platform. If the user is not authenticated and does not otherwise specify which configuration to use (see below), then any attempt to use the client will result in an error asking the user to log in.

For more information on authorization, please see see our Authentication documentation.

Environments

The client supports multiple configuration “environments”. The primary environment for using the GCP based platform is gcp-production, a.k.a. GCP_ENVIRONMENT, while the primary environment for using the AWS based Enterprise Accelerator is aws-production, a.k.a. AWS_ENVIRONMENT. The environment selects not only the client mode (what packages are available in the client) but also the appropriate URLs used by the client to access the Descartes Labs backend services.

There are two mechanisms by which the selection of the environment described above can be overridden.

If the DESCARTESLABS_ENV environment variable is defined when the descarteslabs module (or any submodule) is imported, it will be used to determine the target environment. It should be set to either gcp-production or aws-production as appropriate. This is typically how one would configure the client when invoked from an execution environment set up by the user (for example, AWS Lambda or a Kubernetes workload or other container).

Alternatively, the configuration can be selected at runtime as long as this is done before importing any of the client modules. For this purpose, only three submodules are made available to use prior to and for the purpose of configuring the client: descarteslabs.auth, descarteslabs.config and descarteslabs.exceptions. Importing any other submodule of descarteslabs will trigger automatically configuration, and it will then no longer be possible to configure the client explicitly.

Here is an example of how to configure the client explicitly:

import descarteslabs as dl
dl.select_env(dl.AWS_ENVIRONMENT)

print(f"Using Descartes Labs environment {dl.get_settings().env}")

# now you can import or access anything else from descarteslabs
dl.scenes.search(...)

Settings

The Settings class provides the API for configuration. The current configuration settings are accessible via the get_settings() accesor method. Among other properties, the following may be most useful to the user:

# the currently configured environment
dl.get_settings().env

# True if in AWS mode:
dl.get_settings().aws_client

# True if in GCP mode
dl.get_settings().gcp_client

Please consult the Configuration API documentation for futher information.