Skip to content

Commit

Permalink
Merge pull request #11 from matthewhanson/develop
Browse files Browse the repository at this point in the history
publish 0.3.0
  • Loading branch information
matthewhanson authored Jun 14, 2020
2 parents d829d6c + f57875f commit 09c10a1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

## [v0.3.0] = 2020-06-14

### Changed
- `requester_pays` parameter now argument to s3 session rather than download

## [v0.2.3] - 2020-05-06

### Fixed
Expand Down Expand Up @@ -72,7 +77,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
Initial Release

[Unreleased]: https://github.com/matthewhanson/boto3-utils/compare/master...develop
[v0.2.3]: https://github.com/matthewhanson/boto3-utils/compare/0.2.3...0.2.3
[v0.3.0]: https://github.com/matthewhanson/boto3-utils/compare/0.3.0...0.2.3
[v0.2.3]: https://github.com/matthewhanson/boto3-utils/compare/0.2.2...0.2.3
[v0.2.2]: https://github.com/matthewhanson/boto3-utils/compare/0.2.1...0.2.2
[v0.2.1]: https://github.com/matthewhanson/boto3-utils/compare/0.2.0...0.2.1
[v0.2.0]: https://github.com/matthewhanson/boto3-utils/compare/0.1.3...0.2.0
Expand Down
19 changes: 10 additions & 9 deletions boto3utils/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

class s3(object):

def __init__(self, session=None):
def __init__(self, session=None, requester_pays=False):
self.requester_pays = requester_pays
if session is None:
self.s3 = boto3.client('s3')
else:
Expand Down Expand Up @@ -104,15 +105,15 @@ def upload_json(self, data, url, extra={}, **kwargs):
finally:
rmtree(tmpdir)

def get_object(self, bucket, key, requester_pays=False):
def get_object(self, bucket, key):
""" Get an S3 object """
if requester_pays:
if self.requester_pays:
response = self.s3.get_object(Bucket=bucket, Key=key, RequestPayer='requester')
else:
response = self.s3.get_object(Bucket=bucket, Key=key)
return response

def download(self, uri, path='', **kwargs):
def download(self, uri, path=''):
"""
Download object from S3
:param uri: URI of object to download
Expand All @@ -124,24 +125,24 @@ def download(self, uri, path='', **kwargs):
if path != '':
makedirs(path, exist_ok=True)

response = self.get_object(s3_uri['bucket'], s3_uri['key'], **kwargs)
response = self.get_object(s3_uri['bucket'], s3_uri['key'])

with open(fout, 'wb') as f:
f.write(response['Body'].read())
return fout

def read(self, url, **kwargs):
def read(self, url):
""" Read object from s3 """
parts = self.urlparse(url)
response = self.get_object(parts['bucket'], parts['key'], **kwargs)
response = self.get_object(parts['bucket'], parts['key'])
body = response['Body'].read()
if op.splitext(parts['key'])[1] == '.gz':
body = GzipFile(None, 'rb', fileobj=BytesIO(body)).read()
return body.decode('utf-8')

def read_json(self, url, **kwargs):
def read_json(self, url):
""" Download object from S3 as JSON """
return json.loads(self.read(url, **kwargs))
return json.loads(self.read(url))

def delete(self, url):
""" Remove object from S3 """
Expand Down
2 changes: 1 addition & 1 deletion boto3utils/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.2.3'
__version__ = '0.3.0'

0 comments on commit 09c10a1

Please sign in to comment.