github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/docs/extensions/s3zip/examples/boto3/main.py (about)

     1  #!/usr/bin/env/python
     2  
     3  import boto3
     4  from botocore.client import Config
     5  
     6  s3 = boto3.client('s3',
     7          endpoint_url='http://localhost:9000',
     8          aws_access_key_id='YOUR-ACCESSKEYID',
     9          aws_secret_access_key='YOUR-SECRETACCESSKEY',
    10          config=Config(signature_version='s3v4'),
    11          region_name='us-east-1')
    12  
    13  
    14  def _add_header(request, **kwargs):
    15      request.headers.add_header('x-minio-extract', 'true')
    16  event_system = s3.meta.events
    17  event_system.register_first('before-sign.s3.*', _add_header)
    18  
    19  # List zip contents
    20  response = s3.list_objects_v2(Bucket="your-bucket", Prefix="path/to/file.zip/")
    21  print(response)
    22  
    23  # Download data.csv stored in the zip file
    24  s3.download_file(Bucket='your-bucket', Key='path/to/file.zip/data.csv', Filename='/tmp/data.csv')
    25