Use the AWS SDK for Python with Backblaze B2
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_URLenvironment variable or the
endpoint_urlsetting in the shared AWS config file with your bucket’s S3 endpoint. Note: you must include the
https://prefix in the URL, for example
- 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_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!', )