百度智能云

All Product Document

          MapReduce

          BmrClient

          Configure BmrClient

          BmrClient is the Python client for BMR services and provides a set of methods for interaction between the caller and the BMR services.

          You need to create the configuration file before creating the BmrClient. The configuration file is named as bmr_client_conf.py, and the configuration details are as follows:

          #!/usr/bin/env python
          #coding=utf-8
          
          #import Python standard log module
          import logging
          
          #import BMR configuration administration module and security certification module from Python SDK
          from baidubce.bce_client_configuration import BceClientConfiguration
          from baidubce.auth.bce_credentials import BceCredentials
          
          #set BmrClient’s Host, Access Key ID and Secret Access Key
          host = "bmr.bj.baidubce.com"
          access_key_id = "your-access-key-id"
          secret_access_key = "your-secret-access-key"
          
          #set the log file’s handle and log level
          logger = logging.getLogger('baidubce.services.bmr.bmrclient')
          fh = logging.FileHandler("sample.log")
          fh.setLevel(logging.DEBUG)
          
          #set the order, structure and content of log file output
          formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
          fh.setFormatter(formatter)
          logger.setLevel(logging.DEBUG)
          logger.addHandler(fh)
          
          #create BceClientConfiguration
          config = BceClientConfiguration(credentials=BceCredentials(access_key_id, secret_access_key), 
                                          endpoint=host)

          Notes:

          1. In the above code, the variables access_key_id and secret_access_key are assigned to the user by the system, and they are used to identify the user and verify the signature for the access to Media. The access_key_id corresponds to the “Access Key ID” in the console, and the secret_access_key corresponds to the “Access Key Secret” in the console. For the acquisition, please see the “ACCESSKEY Administration”.
          2. The endpoint parameters of BceClientConfiguration constructor function are only defined with the specified Region-inclusive domain name; the BMR SDK services are currently available in “North China - Beijing” and “South China - Guangzhou”, and Beijing Region’s endpoint domain name is http://bmr.bj.baidubce.com and Guangzhou Region’s endpoint domain name is http://bmr.gz.baidubce.com.

          Create BmrClient

          After completing the above configuration, you can create a BmrClient with the following code:

          import logging
          import bmr_client_conf
          from baidubce.services.bmr.bmr_client import BmrClient
          
          logging.basicConfig(level=logging.DEBUG)
          LOG = logging.getLogger(__name__)
          CONF = bmr_client_conf
          
          bmr_client = BmrClient(CONF.config)

          Parameter Description

          Python SDK sets some basic parameters by default in baidubce/bce_client_configuration.py. If you want to modify the parameter values, you can create your parameter configuration function by referring to this document, and import the function when constructing the BmrClient. The import code for reference is as follows:

          from baidubce.retry_policy import BackOffRetryPolicy
          from baidubce.bce_client_configuration import BceClientConfiguration
          from baidubce.auth.bce_credentials import BceCredentials
          from baidubce.protocol import HTTP
          from baidubce.region import BEIJING
          
          my_policy = BackOffRetryPolicy(max_error_retry=3,
                                         max_delay_in_millis=20 * 1000,
                                         base_interval_in_millis=300)
          
          my_config = BceClientConfiguration(
              credentials=BceCredentials('your-access-key-id', 'your-secret-access-key'),
              endpoint='bmr_service_host',
              protocol=baidubce.protocol.HTTP,
              region=baidubce.region.BEIJING,
              connection_timeout_in_mills=50 * 1000,
              send_buf_size=1024 * 1024,
              recv_buf_size=10 * 1024 * 1024,
              retry_policy=my_policy)
          
          # create BmrClient with my config
          my_client = BmrClient(my_config)

          The parameters are as follows:

          Parameter Description Default Value
          PROTOCOL Protocol baidubce.protocol.HTTP
          REGION Region baidubce.region.BEIJING (currently supports Beijing region only)
          CONNECTION_TIMEOUT_IN_MILLIS Request timeout period (in millisecond) 50 * 1000
          SEND_BUF_SIZE Send buffer size 1024 * 1024
          RECV_BUF_SIZE Receive buffer size 10 * 1024 * 1024
          retry_policy Retry logic 3 times of retry at maximum, timeout 20 * 1000 millisecond, and retry interval 300 milliseconds
          Previous
          Step
          Next
          Exception Handling