Skip to content

Commit 09c10a1

Browse files
Merge pull request #11 from matthewhanson/develop
publish 0.3.0
2 parents d829d6c + f57875f commit 09c10a1

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
66

77
## [Unreleased]
88

9+
## [v0.3.0] = 2020-06-14
10+
11+
### Changed
12+
- `requester_pays` parameter now argument to s3 session rather than download
13+
914
## [v0.2.3] - 2020-05-06
1015

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

7479
[Unreleased]: https://github.com/matthewhanson/boto3-utils/compare/master...develop
75-
[v0.2.3]: https://github.com/matthewhanson/boto3-utils/compare/0.2.3...0.2.3
80+
[v0.3.0]: https://github.com/matthewhanson/boto3-utils/compare/0.3.0...0.2.3
81+
[v0.2.3]: https://github.com/matthewhanson/boto3-utils/compare/0.2.2...0.2.3
7682
[v0.2.2]: https://github.com/matthewhanson/boto3-utils/compare/0.2.1...0.2.2
7783
[v0.2.1]: https://github.com/matthewhanson/boto3-utils/compare/0.2.0...0.2.1
7884
[v0.2.0]: https://github.com/matthewhanson/boto3-utils/compare/0.1.3...0.2.0

boto3utils/s3.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121

2222
class s3(object):
2323

24-
def __init__(self, session=None):
24+
def __init__(self, session=None, requester_pays=False):
25+
self.requester_pays = requester_pays
2526
if session is None:
2627
self.s3 = boto3.client('s3')
2728
else:
@@ -104,15 +105,15 @@ def upload_json(self, data, url, extra={}, **kwargs):
104105
finally:
105106
rmtree(tmpdir)
106107

107-
def get_object(self, bucket, key, requester_pays=False):
108+
def get_object(self, bucket, key):
108109
""" Get an S3 object """
109-
if requester_pays:
110+
if self.requester_pays:
110111
response = self.s3.get_object(Bucket=bucket, Key=key, RequestPayer='requester')
111112
else:
112113
response = self.s3.get_object(Bucket=bucket, Key=key)
113114
return response
114115

115-
def download(self, uri, path='', **kwargs):
116+
def download(self, uri, path=''):
116117
"""
117118
Download object from S3
118119
:param uri: URI of object to download
@@ -124,24 +125,24 @@ def download(self, uri, path='', **kwargs):
124125
if path != '':
125126
makedirs(path, exist_ok=True)
126127

127-
response = self.get_object(s3_uri['bucket'], s3_uri['key'], **kwargs)
128+
response = self.get_object(s3_uri['bucket'], s3_uri['key'])
128129

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

133-
def read(self, url, **kwargs):
134+
def read(self, url):
134135
""" Read object from s3 """
135136
parts = self.urlparse(url)
136-
response = self.get_object(parts['bucket'], parts['key'], **kwargs)
137+
response = self.get_object(parts['bucket'], parts['key'])
137138
body = response['Body'].read()
138139
if op.splitext(parts['key'])[1] == '.gz':
139140
body = GzipFile(None, 'rb', fileobj=BytesIO(body)).read()
140141
return body.decode('utf-8')
141142

142-
def read_json(self, url, **kwargs):
143+
def read_json(self, url):
143144
""" Download object from S3 as JSON """
144-
return json.loads(self.read(url, **kwargs))
145+
return json.loads(self.read(url))
145146

146147
def delete(self, url):
147148
""" Remove object from S3 """

boto3utils/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.2.3'
1+
__version__ = '0.3.0'

0 commit comments

Comments
 (0)