Todos os produtos
Search
Central de documentação

Object Storage Service:Acesso em tempo real a objetos Archive usando o OSS SDK for Python 2.0

Última atualização: Sep 22, 2026

Este tópico descreve como usar o Python SDK V2 para gerenciar o acesso em tempo real a objetos Archive de um bucket.

Observações de uso

  • O código de exemplo deste tópico usa o ID da região cn-hangzhou, da região China (Hangzhou). Por padrão, use o endpoint público para acessar recursos em um bucket. Para acessar os recursos do bucket usando outros serviços da Alibaba Cloud na mesma região em que o bucket está localizado, use um endpoint interno. Para obter mais informações sobre as regiões e os endpoints com suporte no OSS, consulte Regions and endpoints.

Definição do método

Ative o acesso em tempo real a objetos Archive de um bucket

put_bucket_archive_direct_read(request: PutBucketArchiveDirectReadRequest, **kwargs) → PutBucketArchiveDirectReadResult

Consulte se o acesso em tempo real a objetos Archive está ativado para um bucket

get_bucket_archive_direct_read(request: GetBucketArchiveDirectReadRequest, **kwargs) → GetBucketArchiveDirectReadResult

Parâmetros da requisição

Parâmetro

Tipo

Descrição

request

PutBucketArchiveDirectReadRequest

Parâmetros da requisição. Para obter mais informações, consulte PutBucketArchiveDirectReadRequest

GetBucketArchiveDirectReadRequest

Parâmetros da requisição. Para obter mais informações, consulte GetBucketArchiveDirectReadRequest

Parâmetros de resposta

Tipo

Descrição

PutBucketArchiveDirectReadResult

Parâmetros de resposta. Para obter mais informações, consulte PutBucketArchiveDirectReadResult

GetBucketArchiveDirectReadResult

Parâmetros de resposta. Para obter mais informações, consulte GetBucketArchiveDirectReadResult

Para obter a definição completa do método que ativa o acesso em tempo real a objetos Archive de um bucket, consulte put_bucket_archive_direct_read.

Para obter a definição completa do método que consulta se o acesso em tempo real a objetos Archive está ativado para um bucket, consulte get_bucket_archive_direct_read.

Código de exemplo

Ative o acesso em tempo real a objetos Archive de um bucket

Use o código a seguir para ativar o acesso em tempo real a objetos Archive de um bucket.

import argparse
import alibabacloud_oss_v2 as oss

# Create a command-line argument parser and describe the purpose of the script: set the configuration for real-time access of Archive objects for a bucket.
parser = argparse.ArgumentParser(description="put bucket archive direct read sample")

# Define command-line arguments, including the required region, bucket name, endpoint, and whether to enable real-time access of Archive objects.
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)
parser.add_argument('--bucket', help='The name of the bucket.', required=True)
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS')
parser.add_argument('--enabled', help='Specifies whether to enable real-time access of Archive objects for a bucket. Valid values: "true" or "false".', required=True)

def main():
    # Parse the command-line arguments to obtain the values entered by the user.
    args = parser.parse_args()

    # Load access credential information from environment variables for identity verification.
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Create a configuration object using the default SDK configurations and set the authentication provider.
    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider

    # Set the region property of the configuration object based on the command-line arguments provided by the user.
    cfg.region = args.region

    # If a custom endpoint is provided, update the endpoint property in the configuration object.
    if args.endpoint is not None:
        cfg.endpoint = args.endpoint

    # Use the preceding configurations to initialize the OSS client for interacting with OSS.
    client = oss.Client(cfg)

    # Execute a request to set the configuration for real-time access of Archive objects for the specified bucket.
    result = client.put_bucket_archive_direct_read(oss.PutBucketArchiveDirectReadRequest(
            bucket=args.bucket,  # The bucket name.
            archive_direct_read_configuration=oss.ArchiveDirectReadConfiguration(
                enabled=args.enabled.lower() == 'true',  # Convert the string-formatted Boolean value to a Python Boolean type.
            ),
    ))

    # Print the status code and request ID of the operation result to confirm the request status.
    print(f'status code: {result.status_code},'
          f' request id: {result.request_id},'
    )

# When this script is directly executed, call the main function to start processing the logic.
if __name__ == "__main__":
    main()  # The entry point of the script. The program flow starts from here.

Consulte se o acesso em tempo real a objetos Archive está ativado para um bucket

Use o código a seguir para consultar se o acesso em tempo real a objetos Archive está ativado para um bucket.

import argparse
import alibabacloud_oss_v2 as oss

# Create a command-line argument parser and describe the purpose of the script: obtain the configuration for real-time access of Archive objects for a bucket.
parser = argparse.ArgumentParser(description="get bucket archive direct read sample")

# Define command-line arguments, including the required region, bucket name, and endpoint.
parser.add_argument('--region', help='The region in which the bucket is located.', required=True)
parser.add_argument('--bucket', help='The name of the bucket.', required=True)
parser.add_argument('--endpoint', help='The domain names that other services can use to access OSS')

def main():
    # Parse the command-line arguments to obtain the values entered by the user.
    args = parser.parse_args()

    # Load access credential information from environment variables for identity verification.
    credentials_provider = oss.credentials.EnvironmentVariableCredentialsProvider()

    # Create a configuration object using the default SDK configurations and set the authentication provider.
    cfg = oss.config.load_default()
    cfg.credentials_provider = credentials_provider

    # Set the region property of the configuration object based on the command-line arguments provided by the user.
    cfg.region = args.region

    # If a custom endpoint is provided, update the endpoint property in the configuration object.
    if args.endpoint is not None:
        cfg.endpoint = args.endpoint

    # Use the preceding configurations to initialize the OSS client for interacting with OSS.
    client = oss.Client(cfg)

    # Execute a request to obtain the details of the configuration for real-time access of Archive objects for the specified bucket.
    result = client.get_bucket_archive_direct_read(oss.GetBucketArchiveDirectReadRequest(
            bucket=args.bucket,  # The bucket name.
    ))

    # Print the status code and request ID of the operation result to confirm the request status.
    print(f'status code: {result.status_code},'
          f' request id: {result.request_id},'
          f' enabled: {result.archive_direct_read_configuration.enabled if hasattr(result.archive_direct_read_configuration, "enabled") else "Not set"},'  # Whether real-time access of Archive objects is enabled. If it is not set, "Not set" is displayed.
    )

# When this script is directly executed, call the main function to start processing the logic.
if __name__ == "__main__":
    main()  # The entry point of the script. The program flow starts from here.