Initialization

EIP

  • API Reference
    • API function release records
    • API Service Domain Name
    • API Specifications
    • Appendix 1
    • Bandwidth Package Related Interfaces
      • Adjust the bandwidth of the bandwidth package
      • Create bandwidth package
      • Query bandwidth package details
      • Query bandwidth package list information of users
      • Release bandwidth package
      • Update the automatic release time of the bandwidth package
      • Update the name of the bandwidth package
    • DDoS Basic Protection Related Interfaces
      • Modify DDoS basic protection threshold
      • Query DDoS Basic Protection Attack Records
      • Query DDoS basic protection list
    • EIP Related Interfaces
      • Apply for EIP
      • Bind EIP
      • Disable EIP direct
      • EIP bandwidth scaling
      • EIP renewal has been enabled
      • Enable EIP direct
      • Query EIP list in bucket trash
      • Query EIP list
      • Release EIP
      • Release EIPs in the bucket trash
      • Renew EIP
      • Restore EIPs in the bucket trash
      • Selective release of EIP
      • Unbind EIP
      • Unsubscribe prepaid EIP
      • Update EIP Release Protection Switch
    • Error code
    • General Description
    • Inquiry Related
      • Bandwidth package price inquiry
      • EIP Inquiry
      • EIPGROUP Inquiry
      • Shared Traffic Package Inquiry
    • Interface Overview
    • Overview
    • Prerequisites for use
    • Shared Bandwidth Related Interfaces
      • Bandwidth scaling up for EIPGROUP
      • Create EIPGROUP
      • EIPGROUP IP count upgrade
      • EIPGROUP release
      • EIPGROUP renewal
      • EIPGROUP update
      • Migrate EIP from EIPGROUP
      • Migrate EIP into EIPGROUP
      • Query EIPGROUP details
      • Query the EIPGROUP list
      • Unsubscribe prepaid EIPGROUP
    • Shared Traffic Package Related Interfaces
      • Create a shared traffic package
      • Query shared traffic package details
      • Query shared traffic package list
    • TBSP Related Interfaces
      • Add Protection IP Allow List
      • Add Protocol Blocking
      • Add Region Blocking
      • Bind Protection Object
      • Close Protection IP Cleaning
      • Create TBSP
      • Delete Protection IP Allow List
      • Delete Protection Object
      • Delete Protocol Blocking
      • Delete Region Blocking
      • Modify Protection IP Cleaning Threshold
      • Modify Protection IP Protection Level
      • Open Protection IP Cleaning
      • Query Protection IP Allow List
      • Query Protection IP Cleaning Threshold List
      • Query Protocol Blocking List
      • Query Region Blocking List
      • Query TBSP Details
      • Query TBSP List
      • TBSP Capacity dilatation
      • TBSP renew
  • FAQs
    • Billing class
    • Configuration
    • Consultation
    • Security class
  • Function Release Records
  • Operation guide
    • Address pool
    • Bandwidth package
      • Bandwidth scale-up package
      • Cross-border acceleration package
    • Certification
    • DDoS standard protection
    • EIP Instance
      • Create instance
      • EIP Direct Connect
      • IPv6 Termination
      • Manage Alarms
      • Operation Instance
      • Shift Charge
      • View monitoring
    • EIP Self-Service Diagnostics
      • EIP Instance Diagnosis
    • EIPGROUP
      • Bind cloud resources
      • Manage Shared Bandwidth
      • Purchase Shared Bandwidth
      • View monitoring
    • High Defense EIP
    • Identity and access management
    • Recycle bin
    • Shared traffic package
      • Purchase Shared Traffic Package
      • View Shared Traffic Package
    • Tag Management
    • Traffic Burst Service Package
      • Instance management
      • Monitor alarm
      • Protection Configuration
    • Unblocking Center
  • Product Description
    • Application scenarios
    • Product advantages
    • Product Introduction
    • Usage restrictions
  • Product pricing
    • Bandwidth Package Billing
    • EIP Instance Billing
    • EIPGROUP Billing
    • Shared Traffic Package Billing
    • TBSP Billing
  • SDK
    • GO-SDK
      • DDoS Instance
      • EIP Instance
      • EipBp Instance
      • EIPGROUP Instance
      • EipTp Instance
      • Exception handling
      • Initialization
      • Install the SDK Package
      • Overview
    • Java-SDK
      • EIP Instance
      • EipBP Instance
      • EIPGROUP Instance
      • EipTp Instance
      • Exception handling
      • Initialization
      • Install the SDK Package
      • Overview
      • Version history
    • PHP-SDK
      • EIP Instance
      • EipBP Instance
      • EIPGROUP Instance
      • Exception handling
      • Initialization
      • Install the SDK Package
      • Overview
      • Version history
    • Python-SDK
      • EIP Instance
      • EipBP Instance
      • EIPGROUP Instance
      • EipTp Instance
      • Exception handling
      • Initialization
      • Install the SDK Package
      • Overview
      • Version history
  • Service Level Agreement (SLA)
    • EIP Service Level Agreement SLA
    • TBSP Service Level Agreement SLA
  • Typical Practices
    • Bring Your Own Overseas Public IP Address to the Cloud
    • IPv6 Public Network Access
    • Save Public Network Costs
    • TCP Port 25 Restriction Description
All documents
menu
No results found, please re-enter

EIP

  • API Reference
    • API function release records
    • API Service Domain Name
    • API Specifications
    • Appendix 1
    • Bandwidth Package Related Interfaces
      • Adjust the bandwidth of the bandwidth package
      • Create bandwidth package
      • Query bandwidth package details
      • Query bandwidth package list information of users
      • Release bandwidth package
      • Update the automatic release time of the bandwidth package
      • Update the name of the bandwidth package
    • DDoS Basic Protection Related Interfaces
      • Modify DDoS basic protection threshold
      • Query DDoS Basic Protection Attack Records
      • Query DDoS basic protection list
    • EIP Related Interfaces
      • Apply for EIP
      • Bind EIP
      • Disable EIP direct
      • EIP bandwidth scaling
      • EIP renewal has been enabled
      • Enable EIP direct
      • Query EIP list in bucket trash
      • Query EIP list
      • Release EIP
      • Release EIPs in the bucket trash
      • Renew EIP
      • Restore EIPs in the bucket trash
      • Selective release of EIP
      • Unbind EIP
      • Unsubscribe prepaid EIP
      • Update EIP Release Protection Switch
    • Error code
    • General Description
    • Inquiry Related
      • Bandwidth package price inquiry
      • EIP Inquiry
      • EIPGROUP Inquiry
      • Shared Traffic Package Inquiry
    • Interface Overview
    • Overview
    • Prerequisites for use
    • Shared Bandwidth Related Interfaces
      • Bandwidth scaling up for EIPGROUP
      • Create EIPGROUP
      • EIPGROUP IP count upgrade
      • EIPGROUP release
      • EIPGROUP renewal
      • EIPGROUP update
      • Migrate EIP from EIPGROUP
      • Migrate EIP into EIPGROUP
      • Query EIPGROUP details
      • Query the EIPGROUP list
      • Unsubscribe prepaid EIPGROUP
    • Shared Traffic Package Related Interfaces
      • Create a shared traffic package
      • Query shared traffic package details
      • Query shared traffic package list
    • TBSP Related Interfaces
      • Add Protection IP Allow List
      • Add Protocol Blocking
      • Add Region Blocking
      • Bind Protection Object
      • Close Protection IP Cleaning
      • Create TBSP
      • Delete Protection IP Allow List
      • Delete Protection Object
      • Delete Protocol Blocking
      • Delete Region Blocking
      • Modify Protection IP Cleaning Threshold
      • Modify Protection IP Protection Level
      • Open Protection IP Cleaning
      • Query Protection IP Allow List
      • Query Protection IP Cleaning Threshold List
      • Query Protocol Blocking List
      • Query Region Blocking List
      • Query TBSP Details
      • Query TBSP List
      • TBSP Capacity dilatation
      • TBSP renew
  • FAQs
    • Billing class
    • Configuration
    • Consultation
    • Security class
  • Function Release Records
  • Operation guide
    • Address pool
    • Bandwidth package
      • Bandwidth scale-up package
      • Cross-border acceleration package
    • Certification
    • DDoS standard protection
    • EIP Instance
      • Create instance
      • EIP Direct Connect
      • IPv6 Termination
      • Manage Alarms
      • Operation Instance
      • Shift Charge
      • View monitoring
    • EIP Self-Service Diagnostics
      • EIP Instance Diagnosis
    • EIPGROUP
      • Bind cloud resources
      • Manage Shared Bandwidth
      • Purchase Shared Bandwidth
      • View monitoring
    • High Defense EIP
    • Identity and access management
    • Recycle bin
    • Shared traffic package
      • Purchase Shared Traffic Package
      • View Shared Traffic Package
    • Tag Management
    • Traffic Burst Service Package
      • Instance management
      • Monitor alarm
      • Protection Configuration
    • Unblocking Center
  • Product Description
    • Application scenarios
    • Product advantages
    • Product Introduction
    • Usage restrictions
  • Product pricing
    • Bandwidth Package Billing
    • EIP Instance Billing
    • EIPGROUP Billing
    • Shared Traffic Package Billing
    • TBSP Billing
  • SDK
    • GO-SDK
      • DDoS Instance
      • EIP Instance
      • EipBp Instance
      • EIPGROUP Instance
      • EipTp Instance
      • Exception handling
      • Initialization
      • Install the SDK Package
      • Overview
    • Java-SDK
      • EIP Instance
      • EipBP Instance
      • EIPGROUP Instance
      • EipTp Instance
      • Exception handling
      • Initialization
      • Install the SDK Package
      • Overview
      • Version history
    • PHP-SDK
      • EIP Instance
      • EipBP Instance
      • EIPGROUP Instance
      • Exception handling
      • Initialization
      • Install the SDK Package
      • Overview
      • Version history
    • Python-SDK
      • EIP Instance
      • EipBP Instance
      • EIPGROUP Instance
      • EipTp Instance
      • Exception handling
      • Initialization
      • Install the SDK Package
      • Overview
      • Version history
  • Service Level Agreement (SLA)
    • EIP Service Level Agreement SLA
    • TBSP Service Level Agreement SLA
  • Typical Practices
    • Bring Your Own Overseas Public IP Address to the Cloud
    • IPv6 Public Network Access
    • Save Public Network Costs
    • TCP Port 25 Restriction Description
  • Document center
  • arrow
  • EIP
  • arrow
  • SDK
  • arrow
  • Python-SDK
  • arrow
  • Initialization
Table of contents on this page
  • Confirm Endpoint
  • Retrieve access key
  • Create EipClient/EipGroupClient/EipBpClient/EipTpClient
  • Create EipClient/EipGroupClient/EipBpClient/EipTpClient with AK/SK
  • Create EipClient/EipGroupClient/EipBpClient/EipTpClient with STS
  • Configure HTTPS protocol to access EIP/EIPGroup/EipBp/EipTp
  • Configure EipClient/EipGroupClient/EipBpClient
  • Set network parameters

Initialization

Updated at:2025-10-16

Confirm Endpoint

Before configuring the endpoint for SDK usage, please refer toAPI Service Domain Name in API Reference to understand endpoint-related concepts. Baidu AI Cloud currently supports multiple regions. Please refer toRegion Selection Guide. Corresponding information:

Access region Endpoint
Beijing eip.bj.baidubce.com
Guangzhou eip.gz.baidubce.com
Suzhou eip.su.baidubce.com
Hong Kong eip.hkg.baidubce.com
Wuhan eip.fwh.baidubce.com
Baoding eip.bd.baidubce.com

Retrieve access key

To use Baidu AI Cloud EIP, users need a valid AK (Access Key ID) and SK (Secret Access Key) for signature certification. AK/SK are system-assigned strings used to identify users and perform signature certification for EIP. Your AK/SK information can be obtained and understood through the following steps: Register a Baidu AI Cloud account Create AK/SK

Create EipClient/EipGroupClient/EipBpClient/EipTpClient

EipClient/EipGroupClient/EipBpClient/EipTpClient is the Python client for EIP services, enabling developers to interact with EIP services using a variety of provided methods.

Create EipClient/EipGroupClient/EipBpClient/EipTpClient with AK/SK

  1. Before creating EipClient/EipGroupClient, a configuration file must be created for the purpose of configuring EipClient/EipGroupClient/EipBpClient/EipTpClient. In the example below, this file is named eip_sample_conf.py, with the following configuration details:
Python
1#!/usr/bin/env python
2#coding=utf-8
3# Import Python standard logging module
4import logging
5# Import EIP configuration management module and security authentication module from Python SDK
6from baidubce.bce_client_configuration import BceClientConfiguration
7from baidubce.auth.bce_credentials import BceCredentials
8# Set EipClient Host, Access Key ID, and Secret Access Key
9eip_host = "eip.bj.baidubce.com"
10access_key_id = "AK"
11secret_access_key = "SK"
12# Set log file handles and log levels
13logger = logging.getLogger('baidubce.http.bce_http_client')
14fh = logging.FileHandler("sample.log")
15fh.setLevel(logging.DEBUG)
16# Set the order, structure and content of log file output
17formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
18fh.setFormatter(formatter)
19logger.setLevel(logging.DEBUG)
20logger.addHandler(fh)
21# Create BceClientConfiguration instance
22config = BceClientConfiguration(credentials=BceCredentials(access_key_id, secret_access_key), endpoint = eip_host)

Note: For log files, Logging are available the following levels: DEBUG, INFO, WARNING, ERROR, CRITICAL.

In the code above, access_key_id corresponds to “Access Key ID” in the console. secret_access_key corresponds to “Access Key Secret” in the console. For the method to retrieve them, refer to the Guide - Manage ACCESSKEY.

The method above requires users to specify the EIP server domain name by themselves, which can be assigned to the eip_host variable. If not specified, there is no need to pass the endpoint parameter; the default is the Beijing region http://eip.bj.baidubce.com.

  1. After completing the above configuration, refer to the following code to create an EipClient/EipGroupClient/EipBpClient/EipTpClient.
Python
1# Import the EipClient configuration file
2import eip_sample_conf
3		
4# Import Eip-related modules
5from baidubce import exception
6from baidubce.services import eip
7from baidubce.services.eip.eip_client import EipClient
8from baidubce.services.eip.eip_group_client import EipGroupClient
9from baidubce.services.eip.eip_bp_client import EipBpClient
10from baidubce.services.eip.eip_tp_client import EipTpClient
11# Create EipClient
12eip_client = EipClient(eip_sample_conf.config)
13 #Create EipGroupClient
14eip_group_client = EipGroupClient(eip_sample_conf.config)
15 #Create EipBpClient
16eip_bp_client = EipBpClient(eip_sample_conf.config)
17 #Create EipTpClient
18eip_tp_client = EipTpClient(eip_sample_conf.config)

Create EipClient/EipGroupClient/EipBpClient/EipTpClient with STS

EIP allows temporary third-party access authorization using the STS mechanism. STS (Security Token Service) is a temporary authorization service offered by Baidu AI Cloud. With STS, you can issue access credentials with customizable validity periods and permissions to third-party users. These users can then utilize the credentials to directly call Baidu AI Cloud APIs or SDKs to access cloud resources.

To access EIP via STS, users must first request a certification string through the STS client. For instructions on obtaining STS credentials, refer to Baidu AI Cloud STS Usage Guide.

  1. Obtain a temporary token and create a configuration file named "sts_sample_conf.py" for setting up the EipClient/EipGroupClient/EipBpClient/EipTpClient.
Python
1import logging
2from baidubce.bce_client_configuration import BceClientConfiguration
3from baidubce.auth.bce_credentials import BceCredentials
4sts_host = "STS_HOST"
5access_key_id = "AK"
6secret_access_key = "SK"
7logger = logging.getLogger('baidubce.services.sts.stsclient')
8fh = logging.FileHandler("sample.log")
9fh.setLevel(logging.DEBUG)
10formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
11fh.setFormatter(formatter)
12logger.setLevel(logging.DEBUG)
13logger.addHandler(fh)
14config = BceClientConfiguration(credentials=BceCredentials(access_key_id, secret_access_key), endpoint=sts_host)

Note: Currently, when configuring a client with STS, regardless of where the corresponding EIP service endpoint is located, the endpoint must be set to http://sts.bj.baidubce.com.

  1. Create a new StsClient and configure BceClientConfiguration using the obtained temporary token. Create a file "sts_sample.py" to apply for a set of AK, SK and token through StsClient.
Python
1import sts_sample_conf
2from baidubce.services.sts.sts_client import StsClient
3from baidubce.bce_client_configuration import BceClientConfiguration
4from baidubce.auth.bce_credentials import BceCredentials
5sts_client = StsClient(sts_sample_conf.config)
6duration_seconds = 3600
7# you can specify limited permissions with ACL
8access_dict = {}
9access_dict["service"] = "your service words"
10access_dict["region"] = "bj"   
11access_dict["effect"] = "Allow"
12resource = ["*"]
13access_dict["resource"] = resource
14permission = ["READ"]
15access_dict["permission"] = permission
16access_control_list = {"accessControlList": [access_dict]}
17# Create StsClient
18response = sts_client.get_session_token(acl=access_control_list, duration_seconds=duration_seconds)
19sts_ak = str(response.access_key_id)
20sts_sk = str(response.secret_access_key)
21token = response.session_token
22eip_host = "EIP_HOST"
23# Configure BceClientConfiguration instance
24config = BceClientConfiguration(credentials=BceCredentials(sts_ak, sts_sk), endpoint = eip_host, security_token=token)
  1. After completing the above configuration, refer to the following code to create an EipClient/EipGroupClient/EipBpClient/EipTpClient.
Python
1 import sts_sample
2		
3# Import EIP-related modules
4 from baidubce import exception
5 from baidubce.services import eip
6 from baidubce.services.eip.eip_client import EipClient
7 from baidubce.services.eip.eip_group_client import EipGroupClient
8 from baidubce.services.eip.eip_bp_client import EipBpClient
9 from baidubce.services.eip.eip_tp_client import EipTpClient
10	
11# Create EipClient
12 eip_client = EipClient(sts_sample.config)
13 #Create EipGroupClient
14 eip_group_client = EipGroupClient(sts_sample.config)
15 #Create EipBpClient
16 eip_bp_client = EipBpClient(sts_sample.config)
17 #Create EipTpClient
18 eip_tp_client = EipTpClient(eip_sample_conf.config)

Configure HTTPS protocol to access EIP/EIPGroup/EipBp/EipTp

EIP supports HTTPS transport protocol. You can use HTTPS to access the EIP service in the EIP Python SDK in the following two ways:

  • Specify HTTPS in the endpoint:
Python
1 config = bce_client_configuration.BceClientConfiguration(
2    credentials = bce_credentials.BceCredentials(
3        access_key_id = 'your-ak',
4  	    secret_access_key = 'your-sk'
5    ),
6    endpoint = 'https://eip.bj.baidubce.com'
7 )
8 eip_client = eip_client.EipClient(config)
9 eip_group_client = eip_group_client.EipGroupClient(config)
10 eip_bp_client = eip_bp_client.EipBpClient(config)
11 eip_tp_client = eip_tp_client_EipTpClient(config)
  • Set the HTTPS protocol by specifying https in protocol:
Python
1config = bce_client_configuration.BceClientConfiguration(
2    credentials = bce_credentials.BceCredentials(
3        access_key_id = 'your-ak',
4	    secret_access_key = 'your-sk'
5    ),
6    endpoint = 'eip.bj.baidubce.com',
7    protocol = baidubce.protocol.HTTPS
8)
9eip_client = eip_client.EipClient(config)
10eip_group_client = eip_group_client.EipGroupClient(config)
11eip_bp_client = eip_bp_client.EipBpClient(config)
12eip_tp_client = eip_tp_client_EipTpClient(config)

Note: If you specify the protocol parameter while specifying the scheme of the endpoint, the endpoint shall prevail.

Python
1config = bce_client_configuration.BceClientConfiguration(
2    credentials = bce_credentials.BceCredentials(
3        access_key_id = 'your-ak',
4	    secret_access_key = 'your-sk'
5    ),
6    endpoint = 'http://bj.bcebos.com',
7    protocol = baidubce.protocol.HTTPS
8)
9# All in HTTP type
10eip_client = eip_client.EipClient(config)
11eip_group_client = eip_group_client.EipGroupClient(config)
12eip_bp_client = eip_bp_client.EipBpClient(config)
13eip_tp_client = eip_tp_client_EipTpClient(config)

Configure EipClient/EipGroupClient/EipBpClient

Set network parameters

Users can set some network parameters:

Python
1# Set request timeout duration
2eip_sample_conf.config.connection_timeout_in_mills = TIMEOUT
3	    
4# Set receive buffer size
5eip_sample_conf.config.recv_buf_size(BUF_SIZE)
6	
7# Set send buffer size
8eip_sample_conf.config.send_buf_size(BUF_SIZE)
9	
10# Set connection retry policy
11# Three-time exponential backoff retry
12eip_sample_conf.config.retry_policy = BackOffRetryPolicy()
13# No retry
14eip_sample_conf.config.retry_policy = NoRetryPolicy()

Previous
Exception handling
Next
Install the SDK Package