Help Center> Object Storage Service> Python> Preparations (SDK for Python)
Updated on 2024-03-05 GMT+08:00

Preparations (SDK for Python)

Before using OBS SDK for Python to access Huawei Cloud OBS, you need to prepare the service and development environments. To prepare the service environment, you must get a HUAWEI ID and an access key. Both of them are necessary for interaction between OBS SDK for Python and OBS. To ensure successful SDK installation and SDK-based code development and running, you should also set up a local development environment, for example, installing dependencies and development tools.

Preparing a HUAWEI ID

Before using OBS, you must create a HUAWEI ID. For details, see Creating a HUAWEI ID and Enabling Huawei Cloud Services.

Preparing Access Keys

Access keys consist of two parts: an access key ID (AK) and a secret access key (SK). OBS uses access keys to sign requests to make sure that only authorized accounts can access specified OBS resources. Programmatic access must be enabled for an IAM user before the IAM user can get access keys. To enable programmatic access, see Viewing or Modifying IAM User Information. Access keys are explained as follows:

  • One AK maps to only one user but one user can have multiple AKs. OBS authenticates users by their AKs.
  • An SK is required for accessing OBS. Authentication information is generated based on the SK and request headers. AKs and SKs are in one-to-one match.

Access keys are permanent. There are also temporary security credentials (consisting of an AK/SK pair and a security token). Each user can create a maximum of two valid AK/SK pairs. Temporary security credentials can only be used to access OBS within the specified validity period. Once they expire, they must be requested again. For security purposes, you are advised to use temporary security credentials to access OBS. If you want to use permanent access keys, periodically update them. The following describes how to obtain access keys of these two types.

  • To get permanent access keys, do as follows:
    1. Log in to OBS Console.
    2. In the upper right corner, hover over the username and choose My Credentials.
    3. On the My Credentials page, click Access Keys in the navigation pane.
    4. On the Access Keys page, click Create Access Key.
    5. In the displayed dialog box, enter the login password and verification code.
      • If you have not bound an email address or a mobile number yet, only the login password is required.
      • If you have bound both an email address and a mobile number, you can use either of them for verification.
    6. Click OK.
    7. Click Download. The access key file is automatically saved to your browser's default download path.
    8. Open the downloaded credentials.csv file to obtain the AK and SK.
      • Each user can create a maximum of two valid access key pairs.
      • Keep AKs and SKs properly to prevent information leakage. If you click Cancel in the download dialog box, the access keys will not be downloaded and cannot be downloaded later. You can create a new AK/SK pair if needed.
  • To get temporary security credentials, refer to the following:

    Temporary security credentials are issued by the system and are only valid for 15 minutes to 24 hours. They follow the principle of least privilege. When using temporary security credentials, you must use an AK/SK pair and a security token together.

    To obtain them, see Obtaining a Temporary AK/SK and a Security Token.

    OBS is a global service. When obtaining temporary access keys, set the token scope to domain to apply the token to global services. Global services are not differentiated by any project or region.

Setting Up a Development Environment

  • Download a proper Python version from the Python official website and install it.
    • Recommended Python 2.x version: 2.7.x
    • Recommended Python 3.x versions: 3.6, 3.7, 3.8, 3.9, 3.10, and 3.11

    Python 3.5 and earlier versions are not recommended. If you need to use these versions, run the pip install secrets command to install the secrets module. You can install python2-secrets on Python 2.7.

  • Download the latest community version of PyCharm from the PyCharm official website.
  • Run pip install pycryptodome==3.10.1 to install the cryptographic library.