mbed_cloud.sdk.config module

SDK Configuration

Configuration of the Pelion Device Management SDK can be provided in a number of ways. The list is ordered such that the methods at the top of the list have the highest order of precedence and those at the bottom the lowest.

  1. Parameters provided to the mbed_cloud.sdk.sdk.SDK class on instantiation.
  2. Using environment variables.
  3. Environment variables configured via a .env file.

Configuration Parameters

The SDK can be configured with the following parameters:

Parameter Environment Variable Description Optional
api_key MBED_CLOUD_SDK_API_KEY The API key created in the Pelion Device Management Portal. Required
host MBED_CLOUD_SDK_HOST The fully qualified hostname (scheme, host, port) of the REST API. Optional

Production deployment

In a production environments, it is recommended that configuration is stored in environment variables, in a secure manner, this is the equivalent of:

export MBED_CLOUD_SDK_API_KEY=ak_abcdef123

Local Development

For a reproducible local development environment a .env file can be used to configure the SDK without modifying the system’s environment. The file should be named .env and placed at any level of the directory tree between the project’s working directory and the root. Files closer to the working directory take priority.

Example .env file:

MBED_CLOUD_SDK_API_KEY=ak_A644VERY4745LONG64RANDOM3254STRINGW555455ITHA564miXTurOFlowercaseANDUPPERCASELETTERSIintersperseDwithNUMBER5

Warning

Take care to exclude .env files from your version control. Otherwise, you risk exposing your API keys to anyone with read access to your repository.


class mbed_cloud.sdk.config.Config(api_key=None, host=None)

Bases: object

Create a new configuration instance.

If configuration is not supplied then the default configuration from a .env file or environment variables will be used.

Parameters:
  • api_key (str) – (optional) API Key to use for Authentication, if provided this will override all other configuration
  • host (str) – (optional) Host of the Pelion Device Management API, if provided this will override all other configuration
api_key = None
host = None
logger

Instance of the logger.

user_agent

The user-agent used in HTTP requests.