### Get Bucket Lifecycle Configuration Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Retrieves the lifecycle configuration for a bucket. This allows you to review existing rules and their parameters. ```python resp = obsClient.getBucketLifecycle(bucketName='my-bucket') for rule in resp.body.rule: print(f'Rule: {rule.id}, Prefix: {rule.prefix}, Status: {rule.status}') ``` -------------------------------- ### Set Bucket Fetch Policy APIs Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md APIs for managing asynchronous fetch policies for OBS buckets, including setting, getting, and deleting policies. ```python ObsClient.setBucketFetchPolicy ObsClient.getBucketFetchPolicy ObsClient.deleteBucketFetchPolicy ``` -------------------------------- ### Get Bucket Policy Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Retrieves the bucket policy configuration. This is useful for auditing or verifying access rules. ```python resp = obsClient.getBucketPolicy(bucketName='my-bucket') print(resp.body) ``` -------------------------------- ### Get Versioning Status Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Retrieves the current versioning status of a bucket. This confirms if versioning is enabled or suspended. ```python resp = obsClient.getBucketVersioning(bucketName='my-bucket') print(f'Versioning: {resp.body.status}') ``` -------------------------------- ### Generate Temporary Signed URLs for GET and PUT Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Generate pre-signed URLs for temporary access to objects. Specify the HTTP method, bucket name, object key, and expiration time. For PUT requests, you can also specify headers. ```python from obs import ObsClient obsClient = ObsClient( access_key_id='your-ak', secret_access_key='your-sk', server='https://obs.region.myhuaweicloud.com', signature='obs' # or 'v4' ) # Generate signed URL for GET (download) res = obsClient.createSignedUrl( method='GET', bucketName='my-bucket', objectKey='photo.jpg', expires=3600 # Valid for 1 hour ) download_url = res.signedUrl print(f'Download URL: {download_url}') # Generate signed URL for PUT (upload) res = obsClient.createSignedUrl( method='PUT', bucketName='my-bucket', objectKey='upload.txt', expires=3600, headers={'Content-Type': 'text/plain'} ) upload_url = res.signedUrl required_headers = res.actualSignedRequestHeaders print(f'Upload URL: {upload_url}') ``` -------------------------------- ### Access Label Management APIs Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md Manage access labels for OBS resources using these dedicated APIs. Includes setting, getting, and deleting access labels. ```python ObsClient.setAccesslabel ObsClient.getAccessLabel ObsClient.deleteAccessLabel ``` -------------------------------- ### Get Bucket CORS Configuration Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Retrieves the CORS configuration for a bucket. This allows you to inspect the currently active CORS rules. ```python resp = obsClient.getBucketCors(bucketName='my-bucket') for rule in resp.body.corsRule: print(f'Rule: {rule.id}') print(f' Allowed Origins: {rule.allowedOrigin}') print(f' Allowed Methods: {rule.allowedMethod}') ``` -------------------------------- ### Get and Set Object Metadata Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Retrieve existing metadata for an object or update its metadata, including content type, disposition, and custom key-value pairs. Ensure the OBS client is initialized with correct credentials and server endpoint. ```python from obs import ObsClient, SetObjectMetadataHeader obsClient = ObsClient( access_key_id='your-ak', secret_access_key='your-sk', server='https://obs.region.myhuaweicloud.com' ) # Get object metadata resp = obsClient.getObjectMetadata( bucketName='my-bucket', objectKey='photo.jpg' ) if resp.status < 300: for key, value in resp.header: print(f'{key}: {value}') # Set/update object metadata headers = SetObjectMetadataHeader() headers.contentType = 'image/jpeg' headers.contentDisposition = 'attachment; filename="photo.jpg"' headers.cacheControl = 'max-age=86400' metadata = { 'photographer': 'John Doe', 'location': 'New York' } obsClient.setObjectMetadata( bucketName='my-bucket', objectKey='photo.jpg', metadata=metadata, headers=headers ) ``` -------------------------------- ### HTML Form for Browser Upload Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt An example HTML form structure to facilitate browser-based uploads using the generated POST signature. This form includes hidden inputs for policy, signature, and access key. ```html
``` -------------------------------- ### Initialize ObsClient with customized access key retrieval Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md Demonstrates initializing ObsClient by obtaining access keys from environment variables or ECS server temporary credentials. Multiple methods can be combined. ```python from huaweicloudsdkobs.client import ObsClient # Initialize ObsClient by obtaining access keys from environment variables obsClient = ObsClient( ak="YOUR_AK", sk="YOUR_SK", server_endpoint="your_endpoint", security_providers=["env_var"], security_provider_policy="sequence" ) # Initialize ObsClient by obtaining temporary access keys from the ECS server obsClient = ObsClient( ak="YOUR_AK", sk="YOUR_SK", server_endpoint="your_endpoint", security_providers=["ecs_token"], security_provider_policy="sequence" ) # Initialize ObsClient by combining multiple methods to obtain access keys obsClient = ObsClient( ak="YOUR_AK", sk="YOUR_SK", server_endpoint="your_endpoint", security_providers=["env_var", "ecs_token"], security_provider_policy="sequence" ) # Initialize ObsClient by combining multiple methods to obtain access keys and specifying which method goes first obsClient = ObsClient( ak="YOUR_AK", sk="YOUR_SK", server_endpoint="your_endpoint", security_providers=["env_var", "ecs_token"], security_provider_policy="first" ) ``` -------------------------------- ### ObsClient Initialization with Custom Access Key Providers Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md Demonstrates how to initialize ObsClient with customized access key retrieval methods. ```APIDOC ## Initializing ObsClient with Custom Access Key Providers ### Description This section describes how to initialize an instance of ObsClient by providing custom methods for obtaining access keys. This includes using environment variables, temporary access keys from an ECS server, or other user-defined methods. Multiple methods can be combined and prioritized. ### Method Initialization ### Endpoint N/A ### Parameters #### Request Body (for initialization) - **access_key** (string) - Optional - Your Access Key ID. If not provided, it will be obtained using the configured security providers. - **secret_key** (string) - Optional - Your Secret Access Key. If not provided, it will be obtained using the configured security providers. - **security_providers** (list) - Optional - A list of security provider configurations to obtain access keys. Can include environment variables, ECS metadata, or custom providers. - **security_provider_policy** (string) - Optional - Specifies the policy for combining multiple security providers (e.g., 'sequence' or 'first'). - **endpoint** (string) - Required - The endpoint of the OBS service. - **region** (string) - Optional - The region of the OBS service. - **max_redirect_count** (integer) - Optional - The maximum number of redirects allowed for a request. ### Request Example ```python from huaweicloudsdkobs.client import ObsClient # Example using environment variables and a custom provider obs_client = ObsClient( access_key='YOUR_ACCESS_KEY', # Or None to use security_providers secret_key='YOUR_SECRET_KEY', # Or None to use security_providers endpoint='your-obs-endpoint.com', security_providers=[ {'type': 'env'}, {'type': 'custom', 'provider': my_custom_key_provider_function} ], security_provider_policy='sequence' ) ``` ### Response #### Success Response (Initialization) An initialized ObsClient instance. #### Response Example ```python # obs_client is now an instance of ObsClient print(type(obs_client)) ``` ``` -------------------------------- ### Configure Bucket Website Hosting Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Set up static website hosting with index and error documents. Advanced configurations can include routing rules for specific conditions. ```python from obs import ObsClient, WebsiteConfiguration, IndexDocument, ErrorDocument from obs import RoutingRule, Redirect, Condition obsClient = ObsClient( access_key_id='your-ak', secret_access_key='your-sk', server='https://obs.region.myhuaweicloud.com' ) # Basic website configuration website_config = WebsiteConfiguration( indexDocument=IndexDocument(suffix='index.html'), errorDocument=ErrorDocument(key='error.html') ) obsClient.setBucketWebsite(bucketName='my-bucket', website=website_config) # Advanced configuration with routing rules routing_rules = [ RoutingRule( condition=Condition( keyPrefixEquals='docs/', httpErrorCodeReturnedEquals='404' ), redirect=Redirect( protocol='https', hostName='docs.example.com', replaceKeyPrefixWith='documentation/', httpRedirectCode='301' ) ) ] website_config = WebsiteConfiguration( indexDocument=IndexDocument(suffix='index.html'), errorDocument=ErrorDocument(key='404.html'), routingRules=routing_rules ) obsClient.setBucketWebsite(bucketName='my-bucket', website=website_config) # Get website configuration resp = obsClient.getBucketWebsite(bucketName='my-bucket') print(f'Index: {resp.body.indexDocument.suffix}') print(f'Error: {resp.body.errorDocument.key}') # Delete website configuration obsClient.deleteBucketWebsite(bucketName='my-bucket') ``` -------------------------------- ### Initialize ObsClient Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Instantiate the ObsClient for interacting with Huawei Cloud OBS. Supports basic and advanced configurations including authentication, server endpoint, security settings, and connection pooling. Logging can also be initialized. ```python from obs import ObsClient # Basic initialization with access keys obsClient = ObsClient( access_key_id='your-access-key-id', secret_access_key='your-secret-access-key', server='https://obs.region.myhuaweicloud.com' ) ``` ```python from obs import ObsClient # Advanced initialization with all options obsClient = ObsClient( access_key_id='your-access-key-id', secret_access_key='your-secret-access-key', server='https://obs.region.myhuaweicloud.com', is_secure=True, # Use HTTPS signature='obs', # Signature type: 'obs', 'v2', or 'v4' region='your-region', path_style=False, # Use virtual hosting style URLs ssl_verify=False, # SSL certificate verification max_retry_count=3, # Max retries for failed requests timeout=60, # Request timeout in seconds long_conn_mode=True, # Enable connection pooling security_token='your-temp-token' # For temporary credentials ) ``` ```python # Initialize logging obsClient.initLog(log_config='./log.conf', log_name='OBS_LOGGER') ``` ```python # Close client when done obsClient.close() ``` -------------------------------- ### Get Bucket ACL Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Retrieves the Access Control List (ACL) for a specified bucket. This is useful for understanding access permissions. ```python resp = obsClient.getBucketAcl(bucketName='my-bucket') if resp.status < 300: print(f'Owner: {resp.body.owner.owner_id}') for grant in resp.body.grants: print(f'Grantee: {grant.grantee.grantee_id}, Permission: {grant.permission}') ``` -------------------------------- ### Create and Manage Buckets Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Perform bucket operations such as creation, listing, location retrieval, storage info, quota setting, existence checks, and deletion. Use CreateBucketHeader for custom settings during creation. ```python from obs import ObsClient, CreateBucketHeader obsClient = ObsClient( access_key_id='your-ak', secret_access_key='your-sk', server='https://obs.region.myhuaweicloud.com' ) # Create a bucket with default settings resp = obsClient.createBucket('my-bucket') if resp.status < 300: print('Bucket created successfully') else: print(f'Error: {resp.errorCode} - {resp.errorMessage}') ``` ```python # Create bucket with custom settings header = CreateBucketHeader() header.aclControl = 'private' header.storageClass = 'STANDARD' resp = obsClient.createBucket('my-bucket', header=header, location='your-region') ``` ```python # List all buckets resp = obsClient.listBuckets() if resp.status < 300: for bucket in resp.body.buckets: print(f'Bucket: {bucket.name}, Created: {bucket.create_date}') ``` ```python # Get bucket location resp = obsClient.getBucketLocation('my-bucket') print(f'Location: {resp.body.location}') ``` ```python # Get bucket storage info (size and object count) resp = obsClient.getBucketStorageInfo('my-bucket') print(f'Size: {resp.body.size}, Objects: {resp.body.objectNumber}') ``` ```python # Set bucket quota (1GB) obsClient.setBucketQuota('my-bucket', 1024 * 1024 * 1024) ``` ```python # Check if bucket exists resp = obsClient.headBucket('my-bucket') bucket_exists = resp.status < 300 ``` ```python # Delete bucket resp = obsClient.deleteBucket('my-bucket') ``` -------------------------------- ### Use Signed URL with HTTP Client Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Demonstrates how to use a generated signed URL with Python's http.client to download an object. Ensure the URL is correctly parsed. ```python import http.client from urllib.parse import urlparse url = urlparse(download_url) conn = http.client.HTTPSConnection(url.hostname) conn.request('GET', url.path + '?' + url.query) response = conn.getresponse() content = response.read() conn.close() ``` -------------------------------- ### Get Object with CRC64 Integrity Check Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md Retrieve objects from OBS while verifying data integrity using the CRC64 checksum. This is supported for the getObject interface. ```python ObsClient.getObject ``` -------------------------------- ### Uploading Objects Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Demonstrates various methods for uploading objects to OBS, including progress callbacks and uploading streams. ```APIDOC ## POST /api/objects ### Description Uploads an object to an OBS bucket. Supports progress callbacks and uploading data from streams. ### Method POST ### Endpoint /{bucketName}/{objectKey} ### Parameters #### Path Parameters - **bucketName** (string) - Required - The name of the bucket. - **objectKey** (string) - Required - The key of the object. #### Request Body - **file_path** (string) - Required (for `putFile`) - The local path to the file to upload. - **content** (stream) - Required (for `putContent`) - The stream of data to upload. - **progressCallback** (function) - Optional - A callback function to track upload progress. - **headers** (object) - Optional - Additional headers, such as `contentLength` for streams. ``` -------------------------------- ### List Objects with Default Parameters Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Lists objects within a bucket using default parameters, retrieving up to 1000 objects. The response includes key, size, and ETag for each object. ```python from obs import ObsClient, Object, DeleteObjectsRequest obsClient = ObsClient( access_key_id='your-ak', secret_access_key='your-sk', server='https://obs.region.myhuaweicloud.com' ) # List objects with default parameters (up to 1000) resp = obsClient.listObjects(bucketName='my-bucket') if resp.status < 300: for content in resp.body.contents: print(f'Key: {content.key}, Size: {content.size}, ETag: {content.etag}') ``` -------------------------------- ### Initialize Log for ObsClient Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md Fixes an issue where ObsClient.initLog might cause log conflicts by modifying that the logging of ObsClient does not inherit the parent configuration. ```python ObsClient.initLog() ``` -------------------------------- ### Configure Bucket Replication Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Set up cross-region replication for disaster recovery. Rules can specify prefixes, status, destination bucket, storage class, and replication of delete markers and historical objects. ```python from obs import ObsClient, Replication, ReplicationRule obsClient = ObsClient( access_key_id='your-ak', secret_access_key='your-sk', server='https://obs.region.myhuaweicloud.com' ) # Set up replication replication = Replication( agency='obs-replication-agency', # IAM agency with permissions replicationRules=[ ReplicationRule( id='replicate-all', prefix='', # Empty prefix = all objects status='Enabled', bucket='destination-bucket', # Target bucket storageClass='STANDARD', # Storage class in destination deleteData='Enabled', # Replicate delete markers historicalObjectReplication='Enabled' # Replicate existing objects ), ReplicationRule( id='replicate-important', prefix='important/', status='Enabled', bucket='backup-bucket', storageClass='COLD' ) ] ) obsClient.setBucketReplication(bucketName='my-bucket', replication=replication) # Get replication configuration resp = obsClient.getBucketReplication(bucketName='my-bucket') print(f'Agency: {resp.body.agency}') for rule in resp.body.rules: print(f'Rule: {rule.id}, Destination: {rule.bucket}') # Delete replication configuration obsClient.deleteBucketReplication(bucketName='my-bucket') ``` -------------------------------- ### BucketClient Convenience Wrapper Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Utilize BucketClient for streamlined operations on a specific bucket, avoiding repetitive bucket name arguments. This wrapper simplifies common tasks like creating buckets, uploading content, retrieving objects, and managing bucket settings. ```python from obs import ObsClient obsClient = ObsClient( access_key_id='your-ak', secret_access_key='your-sk', server='https://obs.region.myhuaweicloud.com' ) # Create a bucket client bucketClient = obsClient.bucketClient('my-bucket') # All operations automatically use 'my-bucket' bucketClient.createBucket() bucketClient.putContent('hello.txt', 'Hello World!') bucketClient.getObject('hello.txt', loadStreamInMemory=True) bucketClient.setBucketVersioning('Enabled') bucketClient.setBucketAcl(aclControl='public-read') resp = bucketClient.listObjects(prefix='documents/') for content in resp.body.contents: print(content.key) bucketClient.deleteObject('hello.txt') ``` -------------------------------- ### UploadFile Checksum and Checkpoint Parameters Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md Fixes an exception thrown when both `checkSum` and `enableCheckpoint` parameters are True in `uploadFile`. ```python Fixed the issue that an exception is thrown if both the checkSum and enableCheckpoint parameters are specified as True when calling the uploadFile API. ``` -------------------------------- ### Create Bucket API Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md Fixes an issue where the error information reported by the bucket creation API ObsClient.createBucket was incorrect due to protocol negotiation. ```python ObsClient.createBucket ``` -------------------------------- ### Configure Bucket Notifications Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Set up event notifications for object creation or deletion. Supports SMN topic and FunctionGraph triggers with optional filtering rules. ```python from obs import ObsClient, Notification, TopicConfiguration, FunctionGraphConfiguration from obs import FilterRule, EventType obsClient = ObsClient( access_key_id='your-ak', secret_access_key='your-sk', server='https://obs.region.myhuaweicloud.com' ) # Configure SMN topic notification notification = Notification( topicConfigurations=[ TopicConfiguration( id='notify-on-create', topic='urn:smn:region:account:my-topic', events=[EventType.OBJECT_CREATED_ALL], filterRules=[ FilterRule(name='prefix', value='uploads/'), FilterRule(name='suffix', value='.jpg') ] ) ] ) obsClient.setBucketNotification(bucketName='my-bucket', notification=notification) # Configure FunctionGraph trigger notification = Notification( functionGraphConfigurations=[ FunctionGraphConfiguration( id='process-images', functionGraph='urn:fss:region:account:function:default:image-processor:latest', events=[ EventType.OBJECT_CREATED_PUT, EventType.OBJECT_CREATED_POST ], filterRules=[ FilterRule(name='prefix', value='images/'), FilterRule(name='suffix', value='.png') ] ) ] ) obsClient.setBucketNotification(bucketName='my-bucket', notification=notification) # Get notification configuration resp = obsClient.getBucketNotification(bucketName='my-bucket') for topic in resp.body.topicConfigurations: print(f'Topic: {topic.topic}, Events: {topic.events}') # Clear notifications obsClient.setBucketNotification(bucketName='my-bucket', notification=Notification()) ``` -------------------------------- ### Download Object to File Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Downloads an object from OBS and saves it directly to a specified file path on the local filesystem. This is efficient for large files. ```python resp = obsClient.getObject( bucketName='my-bucket', objectKey='photo.jpg', downloadPath='/path/to/save/photo.jpg' ) ``` -------------------------------- ### Upload File with Progress Callback Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Uploads a file to OBS and provides a callback function to monitor the upload progress. Ensure the `progress_callback` function is defined to handle progress updates. ```python def progress_callback(transferred, total, seconds): percentage = (transferred / total) * 100 if total > 0 else 0 print(f'Progress: {percentage:.2f}% ({transferred}/{total} bytes)') resp = obsClient.putFile( bucketName='my-bucket', objectKey='large-file.zip', file_path='/path/to/large-file.zip', progressCallback=progress_callback ) ``` -------------------------------- ### Upload Folder with putFile Method Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md Fix for an issue where `contentType` could be inconsistent when uploading folders using the `putFile` method. ```python ObsClient.putFile ``` -------------------------------- ### ObsClient.getBucketCustomDomain, ObsClient.setBucketCustomDomain, ObsClient.deleteBucketCustomDomain Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md APIs for managing custom domain configurations for OBS buckets. ```APIDOC ## Bucket Custom Domain Management APIs ### Description These APIs allow you to manage custom domain settings for your OBS buckets, enabling you to use your own domain names for accessing bucket objects. ### Methods - `ObsClient.getBucketCustomDomain`: Retrieves the custom domain configuration for a bucket. - `ObsClient.setBucketCustomDomain`: Sets or updates the custom domain configuration for a bucket. - `ObsClient.deleteBucketCustomDomain`: Deletes the custom domain configuration for a bucket. ### Endpoint `/bucket/{bucketName}/customdomain` (Conceptual endpoint, actual implementation may vary) ### Parameters Refer to the SDK documentation for specific parameter details for each method. ``` -------------------------------- ### Batch Download API Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md Introduces the batch download API ObsClient.downloadFiles to support downloading objects by specified prefix, progress return, automatic multipart download of large files, and resumable download. ```python ObsClient.downloadFiles ``` -------------------------------- ### ObsClient.setBucketFetchJob, ObsClient.getBucketFetchJob Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md APIs for managing asynchronous fetch jobs for OBS buckets. ```APIDOC ## Bucket Fetch Job APIs ### Description These APIs enable you to manage asynchronous fetch jobs for your OBS buckets, allowing you to initiate and monitor asynchronous data fetching tasks. ### Methods - `ObsClient.setBucketFetchJob`: Creates or updates an asynchronous fetch job for a bucket. - `ObsClient.getBucketFetchJob`: Retrieves information about an asynchronous fetch job for a bucket. ### Endpoint `/bucket/{bucketName}/fetch-job` (Conceptual endpoint, actual implementation may vary) ### Parameters Refer to the SDK documentation for specific parameter details for each method. ``` -------------------------------- ### Download Object with Progress Callback Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Downloads an object to a file path and provides a callback function to monitor the download progress. Ensure the `progress_callback` function is defined. ```python def progress_callback(transferred, total, seconds): print(f'Downloaded: {transferred}/{total} bytes') resp = obsClient.getObject( bucketName='my-bucket', objectKey='video.mp4', downloadPath='/path/to/video.mp4', progressCallback=progress_callback ) ``` -------------------------------- ### Perform Resumable Upload and Download Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Use uploadFile and downloadFile for automatic resumable transfers with checkpoint support. Configure part size, concurrent threads, and checkpoint file location. ```python from obs import ObsClient, UploadFileHeader, GetObjectHeader obsClient = ObsClient( access_key_id='your-ak', secret_access_key='your-sk', server='https://obs.region.myhuaweicloud.com' ) def progress_callback(transferred, total, seconds): percentage = (transferred / total) * 100 if total > 0 else 0 speed = transferred / seconds if seconds > 0 else 0 print(f'Progress: {percentage:.1f}% Speed: {speed/1024/1024:.2f} MB/s') # Resumable upload with checkpointing resp = obsClient.uploadFile( bucketName='my-bucket', objectKey='huge-file.tar.gz', uploadFile='/path/to/huge-file.tar.gz', partSize=10 * 1024 * 1024, # 10MB parts taskNum=5, # 5 concurrent upload threads enableCheckpoint=True, # Enable checkpoint for resumption checkpointFile='/tmp/upload.checkpoint', progressCallback=progress_callback, isAttachCrc64=True # CRC64 verification ) if resp.status < 300: print('Upload completed successfully') else: print(f'Upload failed: {resp.errorMessage}') # Resumable download with checkpointing header = GetObjectHeader() resp = obsClient.downloadFile( bucketName='my-bucket', objectKey='huge-file.tar.gz', downloadFile='/path/to/download/huge-file.tar.gz', partSize=10 * 1024 * 1024, # 10MB parts taskNum=5, # 5 concurrent download threads enableCheckpoint=True, # Enable checkpoint for resumption checkpointFile='/tmp/download.checkpoint', header=header, progressCallback=progress_callback, isAttachCrc64=True # CRC64 verification ) # Batch download with prefix def task_callback(key, status, result): if status: print(f'Downloaded: {key}') else: print(f'Failed: {key}') obsClient.downloadFiles( bucketName='my-bucket', prefix='backup/', downloadFolder='/local/backup/', taskNum=10, taskCallback=task_callback, progressCallback=progress_callback ) ``` -------------------------------- ### Downloading Objects Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Covers downloading objects from OBS, including options for downloading to memory, files, streams, range downloads, and progress tracking. ```APIDOC ## GET /api/objects/{objectKey} ### Description Downloads an object from an OBS bucket. Supports downloading to memory, files, streams, partial content (range), and progress callbacks. ### Method GET ### Endpoint /{bucketName}/{objectKey} ### Parameters #### Path Parameters - **bucketName** (string) - Required - The name of the bucket. - **objectKey** (string) - Required - The key of the object to download. #### Query Parameters - **loadStreamInMemory** (boolean) - Optional - If true, the entire object content is loaded into memory. - **downloadPath** (string) - Optional - The local path where the object should be saved. - **headers** (object) - Optional - Headers for the download request, e.g., `range` for partial downloads. - **progressCallback** (function) - Optional - A callback function to track download progress. - **isAttachCrc64** (boolean) - Optional - If true, enables CRC64 verification for the download. ``` -------------------------------- ### DownloadFile Retry with CRC64 Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md Fixes an issue where `ObsClient.downloadFile` could not retry after enabling `crc64` if verification failed. ```python Fix the issue where the ObsClient.downloadFile interface cannot retry after enabling crc64, if the verification fails. ``` -------------------------------- ### Download Object to Memory Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Downloads an object from OBS directly into memory. This is suitable for smaller objects where loading the entire content into RAM is feasible. ```python from obs import ObsClient, GetObjectHeader, GetObjectRequest obsClient = ObsClient( access_key_id='your-ak', secret_access_key='your-sk', server='https://obs.region.myhuaweicloud.com' ) # Download to memory resp = obsClient.getObject( bucketName='my-bucket', objectKey='hello.txt', loadStreamInMemory=True ) if resp.status < 300: content = resp.body.buffer print(f'Content: {content.decode("utf-8")}') ``` -------------------------------- ### List Objects with Prefix and Max Keys Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Lists objects within a bucket that match a specified prefix and limits the number of returned objects using `max_keys`. This is useful for filtering objects. ```python resp = obsClient.listObjects( bucketName='my-bucket', prefix='documents/', max_keys=100 ) ``` -------------------------------- ### List Objects with Delimiter (Folder-like Listing) Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Lists objects using a delimiter to simulate folder structures. Common prefixes represent subdirectories, and contents represent objects within the current level. ```python # List with delimiter (folder-like listing) resp = obsClient.listObjects( bucketName='my-bucket', prefix='photos/', delimiter='/' ) # Common prefixes act like "folders" for prefix in resp.body.commonPrefixs: print(f'Folder: {prefix.prefix}') # Contents are "files" in the current "folder" for content in resp.body.contents: print(f'File: {content.key}') ``` -------------------------------- ### ObsClient.downloadFile, ObsClient.getObject, ObsClient.uploadFile, ObsClient.putFile, ObsClient.putContent, ObsClient.appendObject, ObsClient.uploadPart, ObsClient.completeMultipartUpload Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md APIs supporting data integrity checks using CRC64 for various upload and download operations. ```APIDOC ## Data Integrity Check (CRC64) APIs ### Description These APIs support checking data integrity using CRC64 checksums for various object operations, ensuring data accuracy during transfers. ### Methods - `ObsClient.downloadFile`: Downloads an object from OBS, with optional CRC64 validation. - `ObsClient.getObject`: Retrieves an object from OBS, with optional CRC64 validation. - `ObsClient.uploadFile`: Uploads a file to OBS, with optional CRC64 validation. - `ObsClient.putFile`: Uploads a file to OBS, with optional CRC64 validation. - `ObsClient.putContent`: Uploads content to OBS, with optional CRC64 validation. - `ObsClient.appendObject`: Appends data to an object, with optional CRC64 validation. - `ObsClient.uploadPart`: Uploads a part of a multipart upload, with optional CRC64 validation. - `ObsClient.completeMultipartUpload`: Completes a multipart upload, with optional CRC64 validation. ### Parameters - `crc64` (boolean) - Optional - Enables CRC64 checksum validation for the operation. Refer to the SDK documentation for specific parameter details for each method. ``` -------------------------------- ### Query Capacity Statistics Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md Retrieve capacity statistics for OBS buckets, including warm, cold, and deep archive storage sizes. ```python interface adds three types of capacity statistics to be queried: warm, cold, and deepArchiveSize ``` -------------------------------- ### Listing and Managing Objects Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Provides functionality to list objects within a bucket with filtering and pagination, and to delete single or multiple objects. ```APIDOC ## GET /api/objects ### Description Lists objects within an OBS bucket. Supports filtering by prefix, delimiter, and pagination. Also includes endpoints for deleting objects. ### Method GET (for listing), DELETE (for deleting) ### Endpoint /{bucketName} ### Parameters #### Query Parameters (for listing) - **prefix** (string) - Optional - Filters results to objects starting with this prefix. - **max_keys** (integer) - Optional - The maximum number of objects to return in a single request. - **delimiter** (string) - Optional - Used for folder-like listing. Objects with this delimiter are grouped under common prefixes. - **marker** (string) - Optional - Specifies the starting point for the next page of results in a paginated listing. #### Request Body (for batch delete) - **deleteObjectsRequest** (object) - Required - Contains the list of objects to delete. - **quiet** (boolean) - Optional - If true, suppresses success details for deleted objects. - **objects** (array) - Required - A list of objects to delete, each with a `key` property. - **key** (string) - Required - The key of the object to delete. - **versionId** (string) - Optional - The version ID of the object to delete (if versioning is enabled). ### Response (for listing) - **contents** (array) - List of objects found. - **commonPrefixs** (array) - List of common prefixes (folders) found. - **is_truncated** (boolean) - Indicates if the listing is truncated and more results are available. - **next_marker** (string) - The marker for the next page of results. ``` -------------------------------- ### ObsClient.putBucketPublicAccessBlock, ObsClient.getBucketPublicAccessBlock, ObsClient.deleteBucketPublicAccessBlock, ObsClient.getBucketPolicyPublicStatus, ObsClient.getBucketPublicStatus Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md APIs for managing public access block settings and status for OBS buckets. ```APIDOC ## Bucket Public Access Block APIs ### Description These APIs provide functionality to configure and query public access block settings for OBS buckets, helping to prevent accidental public exposure of your data. ### Methods - `ObsClient.putBucketPublicAccessBlock`: Configures public access block settings for a bucket. - `ObsClient.getBucketPublicAccessBlock`: Retrieves the public access block configuration for a bucket. - `ObsClient.deleteBucketPublicAccessBlock`: Removes the public access block configuration from a bucket. - `ObsClient.getBucketPolicyPublicStatus`: Checks the public status of a bucket's policy. - `ObsClient.getBucketPublicStatus`: Retrieves the overall public access status of a bucket. ### Endpoint `/bucket/{bucketName}/access-control/public-access-block` (Conceptual endpoint, actual implementation may vary) ### Parameters Refer to the SDK documentation for specific parameter details for each method. ``` -------------------------------- ### Enable Bucket Versioning Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Enables versioning for a bucket, which keeps multiple versions of objects. This helps protect against accidental overwrites or deletions. ```python obsClient.setBucketVersioning(bucketName='my-bucket', status='Enabled') ``` -------------------------------- ### Set Bucket Custom Domain API Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md Use these APIs to manage custom domain configurations for OBS buckets. Requires bucket name and custom domain details. ```python ObsClient.getBucketCustomDomain ObsClient.setBucketCustomDomain ObsClient.deleteBucketCustomDomain ``` -------------------------------- ### List Object Versions Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Lists all versions of objects within a bucket, including the latest and previous versions. This is useful for managing historical data. ```python resp = obsClient.listVersions(bucketName='my-bucket') for version in resp.body.versions: print(f'Key: {version.key}, VersionId: {version.versionId}, IsLatest: {version.isLatest}') ``` -------------------------------- ### ObsClient.setBucketFetchPolicy, ObsClient.getBucketFetchPolicy, ObsClient.deleteBucketFetchPolicy Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md APIs for managing asynchronous fetch policies for OBS buckets. ```APIDOC ## Bucket Fetch Policy APIs ### Description These APIs allow you to manage asynchronous fetch policies for your OBS buckets, controlling how data is fetched asynchronously. ### Methods - `ObsClient.setBucketFetchPolicy`: Sets an asynchronous fetch policy for a bucket. - `ObsClient.getBucketFetchPolicy`: Retrieves the asynchronous fetch policy for a bucket. - `ObsClient.deleteBucketFetchPolicy`: Deletes the asynchronous fetch policy for a bucket. ### Endpoint `/bucket/{bucketName}/fetch-policy` (Conceptual endpoint, actual implementation may vary) ### Parameters Refer to the SDK documentation for specific parameter details for each method. ``` -------------------------------- ### Client-Side Encryption Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md Introduces a crypto client for encrypting objects at the client side before uploading them to OBS. ```python Add crypto client, could encrypt object at client side. ``` -------------------------------- ### Set Bucket ACL Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Configure access control lists for buckets. Use canned ACL strings for common permission settings. ```python from obs import ObsClient, ACL, Owner, Grant, Grantee, Permission obsClient = ObsClient( access_key_id='your-ak', secret_access_key='your-sk', server='https://obs.region.myhuaweicloud.com' ) # Set bucket ACL using canned ACL obsClient.setBucketAcl( bucketName='my-bucket', aclControl='public-read' # Options: private, public-read, public-read-write ) ``` -------------------------------- ### Test Bucket CORS with OPTIONS Request Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Performs an OPTIONS request to test CORS preflight settings for a bucket. This helps verify if the server will allow the requested origin, methods, and headers. ```python from obs import Options options = Options( origin='https://www.example.com', accessControlRequestMethods=['PUT', 'GET'], accessControlRequestHeaders=['Authorization', 'Content-Type'] ) resp = obsClient.optionsBucket(bucketName='my-bucket', option=options) print(f'Allowed Methods: {resp.body.accessControlAllowMethods}') print(f'Allowed Headers: {resp.body.accessControlAllowHeaders}') ``` -------------------------------- ### ObsClient.setAccesslabel, ObsClient.getAccessLabel, ObsClient.deleteAccessLabel Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md APIs for managing access labels on OBS buckets. ```APIDOC ## Access Label Management APIs ### Description These APIs provide functionality to manage access labels associated with your OBS buckets, allowing for granular control over access permissions. ### Methods - `ObsClient.setAccesslabel`: Sets or updates an access label for a bucket. - `ObsClient.getAccessLabel`: Retrieves the access labels configured for a bucket. - `ObsClient.deleteAccessLabel`: Removes an access label from a bucket. ### Endpoint `/bucket/{bucketName}/accesslabel` (Conceptual endpoint, actual implementation may vary) ### Parameters Refer to the SDK documentation for specific parameter details for each method. ``` -------------------------------- ### Service Orchestration APIs Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md APIs for service orchestration, as detailed in obs/workflow.py. ```APIDOC ## POST /api/services/orchestration ### Description Executes a service orchestration task. ### Method POST ### Endpoint /api/services/orchestration ### Parameters #### Request Body - **workflow_definition** (object) - Required - The definition of the workflow to be orchestrated. - **parameters** (object) - Optional - Parameters for the workflow. ### Request Example ```json { "workflow_definition": { "steps": [ { "name": "step1", "action": "s3:GetObject", "input": { "bucket": "my-bucket", "key": "my-object" } } ] }, "parameters": { "param1": "value1" } } ``` ### Response #### Success Response (200) - **task_id** (string) - The ID of the orchestration task. - **status** (string) - The status of the task. #### Response Example ```json { "task_id": "a1b2c3d4-e5f6-7890-1234-567890abcdef", "status": "RUNNING" } ``` ``` -------------------------------- ### Range Download (Partial Content) Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Downloads a specific byte range of an object from OBS into memory. Use `GetObjectHeader` to specify the desired byte range. ```python headers = GetObjectHeader() headers.range = 'bytes=0-1023' # First 1KB resp = obsClient.getObject( bucketName='my-bucket', objectKey='large-file.bin', headers=headers, loadStreamInMemory=True ) ``` -------------------------------- ### ObsClient.setBucketLifecycle Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md API for setting bucket lifecycle rules, including fragment expiration. ```APIDOC ## Bucket Lifecycle Management API ### Description This API allows you to configure lifecycle rules for your OBS buckets, including setting expiration times for object fragments. ### Method `ObsClient.setBucketLifecycle` ### Endpoint `/bucket/{bucketName}/lifecycle` (Conceptual endpoint, actual implementation may vary) ### Parameters Refer to the SDK documentation for specific parameter details, including options for fragment expiration. ``` -------------------------------- ### Paginated Object Listing Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Performs a paginated listing of objects in a bucket, retrieving objects in batches using a marker. This is essential for handling buckets with a large number of objects. ```python # Paginated listing next_marker = None while True: resp = obsClient.listObjects( bucketName='my-bucket', max_keys=100, marker=next_marker ) for content in resp.body.contents: print(content.key) if not resp.body.is_truncated: break next_marker = resp.body.next_marker ``` -------------------------------- ### Configure Requester Pays function Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md Configure the Requester Pays function for a bucket using setBucketRequestPayment. This allows the requester to pay for data transfer and requests. ```python from huaweicloudsdkobs.client import ObsClient obsClient = ObsClient(ak="YOUR_AK", sk="YOUR_SK", server_endpoint="your_endpoint") # Configure Requester Pays function resp = obsClient.setBucketRequestPayment(bucketName="sample", requestPaymentConfiguration={'Payer': 'Requester'}) if resp.status < 300: print("Requester Pays function configured successfully.") else: print("Failed to configure Requester Pays function.") ``` -------------------------------- ### Set Bucket Fetch Job APIs Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md APIs for managing asynchronous fetch jobs associated with OBS buckets. ```python ObsClient.setBucketFetchJob ObsClient.getBucketFetchJob ``` -------------------------------- ### Upload Objects to OBS Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Upload content to OBS buckets using putContent for strings/streams or putFile for local files. Supports custom headers, metadata, and progress callbacks. ```python from obs import ObsClient, PutObjectHeader obsClient = ObsClient( access_key_id='your-ak', secret_access_key='your-sk', server='https://obs.region.myhuaweicloud.com' ) # Upload string content resp = obsClient.putContent( bucketName='my-bucket', objectKey='hello.txt', content='Hello OBS!' ) if resp.status < 300: print(f'Object URL: {resp.body.objectUrl}') print(f'ETag: {dict(resp.header).get("etag")}') ``` ```python # Upload with custom headers and metadata headers = PutObjectHeader() headers.contentType = 'text/plain' headers.storageClass = 'STANDARD' metadata = { 'author': 'developer', 'version': '1.0' } resp = obsClient.putContent( bucketName='my-bucket', objectKey='document.txt', content='Document content', metadata=metadata, headers=headers ) ``` ```python # Upload a file resp = obsClient.putFile( bucketName='my-bucket', objectKey='photo.jpg', file_path='/path/to/photo.jpg' ) ``` -------------------------------- ### Download Object as Stream for Processing Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Downloads an object from OBS as a stream, allowing for real-time processing or writing to a file in chunks. This is memory-efficient for large objects. ```python resp = obsClient.getObject( bucketName='my-bucket', objectKey='large-file.bin' ) if resp.status < 300: response = resp.body.response with open('/path/to/output.bin', 'wb') as f: while True: chunk = response.read(65536) if not chunk: break f.write(chunk) response.close() ``` -------------------------------- ### Log File Handle Closure Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md Fixes an issue where ObsClient.close fails to close the log file handle correctly. ```python ObsClient.close() ``` -------------------------------- ### Generate POST Signature for Browser Uploads Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Generate the necessary policy, signature, and Access Key ID for browser-based uploads using a POST request. The object key can use templates for dynamic filenames. ```python res = obsClient.createPostSignature( bucketName='my-bucket', objectKey='uploads/${filename}', # Template for filename expires=3600, formParams={ 'acl': 'public-read', 'content-type': 'image/jpeg' } ) print(f'Policy: {res.policy}') print(f'Signature: {res.signature}') print(f'AccessKeyId: {res.accessKeyId}') ``` -------------------------------- ### Set Bucket Encryption API Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md Introduces bucket encryption APIs. Currently, only SSE-KMS encryption is supported. ```python ObsClient.setBucketEncryption ``` ```python ObsClient.getBucketEncryption ``` ```python ObsClient.deleteBucketEncryption ``` -------------------------------- ### Capacity Statistics APIs Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md APIs to query capacity statistics for warm, cold, and deep archive storage. ```APIDOC ## Bucket Capacity Statistics APIs ### Description These APIs provide the ability to query capacity statistics for your OBS buckets, including counts for warm, cold, and deep archive storage. ### Methods - Interface to query capacity statistics (specific method name not provided in source). ### Parameters - `types` (list of strings) - Required - Specifies the types of capacity statistics to query (e.g., 'warm', 'cold', 'deepArchiveSize'). Refer to the SDK documentation for specific parameter details. ``` -------------------------------- ### Asynchronous fetch and service orchestration APIs Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md This snippet relates to the usage of asynchronous fetch and service orchestration APIs within the OBS Python SDK. Specific implementation details are found in obs/workflow.py. ```python # This is a placeholder for code related to asynchronous fetch and service orchestration APIs. # Actual implementation details are in obs/workflow.py. pass ``` -------------------------------- ### Import OBS Package Forking Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md Fixes the issue that the process is forked when the OBS package is imported to the Linux OS. ```python import OBS ``` -------------------------------- ### Set Bucket Policy Source: https://context7.com/huaweicloud/huaweicloud-sdk-python-obs/llms.txt Applies a bucket policy defined in JSON format to grant specific permissions. Ensure the policy JSON is correctly formatted and adheres to the required structure. ```python policy = '''{ "Version": "2008-10-17", "Statement": [{ "Sid": "PublicRead", "Effect": "Allow", "Principal": {"AWS": "*"}, "Action": ["s3:GetObject"], "Resource": ["arn:aws:s3:::my-bucket/*"] }] }''' obsClient.setBucketPolicy(bucketName='my-bucket', policyJSON=policy) ``` -------------------------------- ### Bucket Encryption Support Source: https://github.com/huaweicloud/huaweicloud-sdk-python-obs/blob/master/README.md Fixes the issue that bucketClient does not support bucket encryption APIs. ```python bucketClient ```