Filebase
Search…
AWS SDK - Python
Learn how to use the AWS SDK for Python with Filebase.

What is AWS SDK - Python?

AWS SDKs (software development kits) help simplify coding and application development by supporting and providing code objects for use with S3-compatible services. There are a variety of different AWS SDKs, each for a different coding language. This guide covers AWS SDK - Python (boto3).
This guide was written using Ubuntu 20.04 and tested using the command line interface. If you are using an Integrated Development Environment (IDE), the installation of dependencies and modules will vary.

Prerequisites:

  • Download and install Python3 in your environment.
  • Download and install the AWS SDK for Python (boto3).
  • Have Your Filebase Access and Secret Keys. Learn how to view your access keys here.
  • Create a Filebase Bucket. Learn how to create a bucket here.

Create a Bucket

The following code example creates a new Filebase bucket. Replace the following values in the code to match your configuration:
  • filebase-access-key: Your Filebase Access Key
  • filebase-secret-key: Your Filebase Secret Key
  • new-filebase-bucket: The Intended New Bucket Name
Bucket names must be unique across all Filebase users, be between 3 and 63 characters long, and can contain only lowercase characters, numbers, and dashes.
Buckets created through this method will be automatically created on the Storj network.
1
import boto3
2
3
s3 = boto3.client('s3',
4
endpoint_url='https://s3.filebase.com',
5
aws_access_key_id="filebase-access-key",
6
aws_secret_access_key="filebase-secret-key")
7
8
bucket_name = "new-filebase-bucket"
9
10
s3.create_bucket(Bucket=bucket_name)
Copied!

Upload an Object

The following code example uploads an object to the specified bucket. Replace the following values in the code to match your configuration:
  • filebase-access-key: Your Filebase Access Key
  • filebase-secret-key: Your Filebase Secret Key
  • filebase-bucket-name: The Filebase Bucket Name
  • /path/to/object/to/upload: The file path to the object that you want to be uploaded
  • object-name: The desired object name once uploaded
1
import boto3
2
3
s3 = boto3.client('s3',
4
endpoint_url='https://s3.filebase.com',
5
aws_access_key_id="filebase-access-key",
6
aws_secret_access_key="filebase-secret-key")
7
8
file_path = "/path/to/object/to/upload"
9
bucket_name = "filebase-bucket-name"
10
key_name = "object-name"
11
12
s3.put_object(Body=file_path, Bucket=bucket_name, Key=key_name)
Copied!

Download an Object

The following code example downloads an object from the specified bucket. Replace the following values in the code to match your configuration:
  • filebase-access-key: Your Filebase Access Key
  • filebase-secret-key: Your Filebase Secret Key
  • filebase-bucket-name: The Filebase Bucket Name
  • object-name: The object to be downloaded
1
import boto3
2
3
s3 = boto3.client('s3',
4
endpoint_url='https://s3.filebase.com',
5
aws_access_key_id="filebase-access-key",
6
aws_secret_access_key="filebase-secret-key")
7
8
bucket_name = "filebase-bucket-name"
9
key_name = "object-name"
10
11
s3.get_object(Bucket=bucket_name, Key=key_name)
Copied!

Delete an Object

The following code example deletes an object from the specified bucket. Replace the following values in the code to match your configuration:
  • filebase-access-key: Your Filebase Access Key
  • filebase-secret-key: Your Filebase Secret Key
  • filebase-bucket-name: The Filebase Bucket Name
  • object-name: The object to be downloaded
1
import boto3
2
3
s3 = boto3.client('s3',
4
endpoint_url='https://s3.filebase.com',
5
aws_access_key_id="filebase-access-key",
6
aws_secret_access_key="filebase-secret-key")
7
8
bucket_name = "filebase-bucket-name"
9
10
key_name = "object-name"
11
12
s3.delete_object(Bucket=bucket_name, Key=key_name)
Copied!
For more information on the AWS SDK for Python, check out the documentation here.
If you have any questions, please send us an email at [email protected].
Last modified 1mo ago