- Print
- DarkLight
Use the AWS SDK for Python with Backblaze B2
- Print
- DarkLight
You can take advantage of Backblaze B2 Cloud Storage using the AWS SDK for Python alongside the Backblaze S3-Compatible API.
You need to point the endpoint_url
to the S3 endpoint of the Backblaze B2 account to which you are connecting, along with supplying an Application Key and Key ID for the account.
Backblaze also maintains a Python SDK for the B2 Native API. You can find this project here.
To use the AWS SDK for Python with Backblaze B2, you must:
- Use version AWS SDK for Python (Boto3) 1.28.0 or greater. Older versions do not support easy configuration of a custom endpoint using the service-specific endpoint feature.
- Configure the
AWS_ENDPOINT_URL
environment variable or theendpoint_url
setting in the shared AWS config file with your bucket’s S3 endpoint. Note: you must include thehttps://
prefix in the URL, for examplehttps://s3.us-west-004.backblazeb2.com
. - Configure your application key and application key ID via one of the methods supported by the AWS SDK for Python (Boto3). Note: the Backblaze application key ID is equivalent to the AWS access key id and the Backblaze application key itself is equivalent to the AWS secret access key.
The following example demonstrates how to create a bucket and upload data after having configured the AWS_ENDPOINT_URL
, AWS_ACCESS_KEY_ID
and AWS_SECRET_ACCESS_KEY
using either environment variables or the shared AWS config file:
import boto3
s3 = boto3.client('s3')
s3.create_bucket(Bucket='<bucket-name>')
s3.put_object(
Bucket='<bucket-name>',
Key='hello.txt',
Body='Hello, World!',
)
The S3-Compatible API allows 1000’s of integrations to natively work with Backblaze B2. If you are new to the S3-Compatible API, click here. If you have issues using this SDK with Backblaze B2, let us know by emailing us at [email protected].