pip install pysimplestorageservice
git clone https://github.com/poteralski/pysimplestorageservice.git
cd pysimplestorageservice
python setup.py install
python setup.py develop
from pysimplestorageservice import AmazonAWSManager
amazon = AmazonAWSManager(
access_key=AWS_ACCESS_KEY_ID,
secret_key=AWS_SECRET_ACCESS_KEY
)
result = amazon.get(
bucket=TEST_BUCKET,
prefix=TEST_DIR,
filename=TEST_FILE,
)
output = open(TEST_FILE, "wb")
output.write(result)
output.close()
from pysimplestorageservice import AmazonAWSManager
amazon = AmazonAWSManager(
access_key=AWS_ACCESS_KEY_ID,
secret_key=AWS_SECRET_ACCESS_KEY
)
files = amazon.get_file_list(
bucket=TEST_BUCKET,
prefix=TEST_DIR+'/',
)
print files
from pysimplestorageservice import AmazonAWSManager
amazon = AmazonAWSManager(
access_key=AWS_ACCESS_KEY_ID,
secret_key=AWS_SECRET_ACCESS_KEY
)
filaname = 'test2.jpg'
file1 = open(filaname, 'r').read()
respond = amazon.put(filename=filaname, file=file1, prefix='test', bucket=TEST_BUCKET)
You can use this class for authenticate you own requests, for example:
Argument | Type | Description |
---|---|---|
bucket |
str |
Amazon S3 Bucket Name |
method |
str |
Amazon S3 Method |
canonical_uri='/' |
str |
Path to file/files |
payload='' |
str |
Payloads to sign |
querystring={} |
Dict |
HTTP QueryString to sign |
from pysimplestorageservice.auth import AuthSigV4
auth = AuthSigV4(access_key='access_key', secret_key='secret_key')
headers = auth.get_headers('bucket-name', 'GET', canonical_uri='path/to/file.jpg'
file_url = self.__build_endpoint(bucket, prefix, filename)
r = requests.get(file_url, headers=headers)
based on Authenticating Requests (AWS Signature Version 4)
Problem with connect to Servers with Signature Version 4 Auth like Frankfurt
This package is available under the Apache License, Version 2.0.