Skip to content

Python and JavaScript SDKs

Any AWS S3 SDK works with Hive Buckets. Set three things: the endpoint, the region auto and path-style addressing. Keep your access key in environment variables:

Terminal window
export HIVE_BUCKETS_ENDPOINT=https://s3.dockhive.io
export HIVE_BUCKETS_ACCESS_KEY_ID=DH...
export HIVE_BUCKETS_SECRET_ACCESS_KEY=...
Terminal window
pip install boto3
import os
import boto3
from botocore.config import Config
s3 = boto3.client(
"s3",
endpoint_url=os.environ["HIVE_BUCKETS_ENDPOINT"],
aws_access_key_id=os.environ["HIVE_BUCKETS_ACCESS_KEY_ID"],
aws_secret_access_key=os.environ["HIVE_BUCKETS_SECRET_ACCESS_KEY"],
region_name="auto",
config=Config(signature_version="s3v4", s3={"addressing_style": "path"}),
)
from boto3.s3.transfer import TransferConfig
BUCKET = "my-app-uploads"
# Small object from memory
s3.put_object(Bucket=BUCKET, Key="notes/hello.txt", Body=b"hello", ContentType="text/plain")
# Any size file from disk: multipart is used automatically above the threshold
transfer = TransferConfig(multipart_threshold=64 * 1024**2, multipart_chunksize=16 * 1024**2)
s3.upload_file("video.mp4", BUCKET, "videos/video.mp4", Config=transfer)
# Download
obj = s3.get_object(Bucket=BUCKET, Key="notes/hello.txt")
print(obj["Body"].read())
s3.download_file(BUCKET, "videos/video.mp4", "copy.mp4")
# List (paginated)
for page in s3.get_paginator("list_objects_v2").paginate(Bucket=BUCKET, Prefix="videos/"):
for item in page.get("Contents", []):
print(item["Key"], item["Size"])
# Delete
s3.delete_object(Bucket=BUCKET, Key="notes/hello.txt")

Keep part sizes at 100 MB or less. The SDK defaults (8 MB for boto3, 5 MB for Upload) are fine. See Limits.

Give someone a link that works for a limited time, up to 7 days, without sharing your key. See Presigned URLs and browser uploads for uploads and POST forms.

url = s3.generate_presigned_url(
"get_object",
Params={"Bucket": "my-app-uploads", "Key": "reports/report.pdf"},
ExpiresIn=3600, # seconds; at most 604800 (7 days)
)

Go (aws-sdk-go-v2, set UsePathStyle: true), PHP (aws/aws-sdk-php, use_path_style_endpoint), Java, .NET, Ruby and Rust SDKs work the same way: endpoint, region auto, path style, your DH... key.