stream and (de)serialize s3 objects with no local footprint
Project description
s3-streaming: handling (big) S3 files like regular files
Storing, retrieving and using files in S3 is a regular activity so it should be easy. It should also ...
- stream the data
- have an api that is python file-io like
- handle some of the desearization and compression stuff because why not
Install
pip install s3-streaming
Streaming S3 objects like regular files
The basics
Opening and reading S3 objects is similar to regular python io. The only difference is that you need to provide a
boto3.session.Session
instance to handle the bucket access.
import boto3
from s3streaming import s3_open
with s3_open('s3://bucket/key', boto_session=boto3.session.Session()) as f:
for next_line in f:
print(next_line)
Injecting deserialization and compression handling in stream
Consider a file that is gzip
compressed and contains lines of json
. There's some boilerplate in dealing with that,
but why bother? Just handle that in stream.
from s3streaming import s3_open, deserialize, compression
reader_settings = dict(
boto_session=boto3.session.Session(),
deserializer=deserialize.json_lines,
compression=compression.gzip
)
with s3_open('s3://bucket/key.gzip', **reader_settings) as f:
for next_line in f:
print(next_line.keys()) # because the file was decompressed ...
print(next_line.values()) # ... and the json is now a loaded dict!
Other deserialize
options include
csv
csv_as_dict
tsv
tsv_as_dict
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
s3-streaming-0.0.1a0.tar.gz
(3.2 kB
view hashes)
Built Distribution
Close
Hashes for s3_streaming-0.0.1a0-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb2da5c8f6afd938a1d2c6020d320413976b217aba0294ad99a02a207dba8f26 |
|
MD5 | 249700c1ded558bf6ffeaf7a10660fc3 |
|
BLAKE2b-256 | 0c384cc6b8b0681d12ba74d904a11acc6ded6800ac7ae9ca46955f6769657d2e |