Python Boto3

This guide details the steps needed to install and use the Boto3 library for Python.

The SDK is composed of two key Python packages: Botocore (the library providing the low-level functionality) and Boto3 (the package implementing the Python SDK itself).

Installation

Install the latest Boto3 release via pip:

1pip install boto3

Using Boto3

To use Boto3, you must first import it, indicate that you are going to use S3 service, provide Key and Secret access details, and set Tebi S3 endpoint URL:

1import boto3
2
3# Let's use S3
4s3 = boto3.resource(
5    service_name='s3',
6    aws_access_key_id='<PUT_YOUR_KEY>',
7    aws_secret_access_key='<PUT_YOUR_SECRET>',
8    endpoint_url='https://s3.tebi.io'
9)

Now that you have an S3 resource, you can send requests to the service. The following code uses the buckets collection to print out all bucket names:

10# Print out bucket names
11for bucket in s3.buckets.all():
12    print(bucket.name)

You can also upload and download binary data. For example, the following uploads a new file to S3, assuming that the bucket my-bucket already exists:

13# Upload a new file
14data = open('test.jpg', 'rb')
15s3.Bucket('my-bucket').put_object(Key='test.jpg', Body=data)

For more examples, please refer to the official Boto3 documentation examples, full Boto3 S3 reference is available here.