Skip to main content
Python Software Foundation 20th Year Anniversary Fundraiser  Donate today!

Encode and decode concatenated objects as streams

Project description

Encoding a JSON iterator into a stream:

def gen_records():
    yield b'{"foo": "bar"}'
    yield b'{"baz": [1, 2, 3]}'

stream = streamcat.iterator_to_stream(gen_records())

# `stream` can then be used just like any other `io.RawIOBase`
with open('/tmp/jsoncat', 'wb') as destination:
    shutil.copyfileobj(stream, destination)

Decoding a stream into a generator:

decoder = json.JSONDecoder()
with open('/tmp/jsoncat', 'rb') as source:
    records = streamcat.stream_to_iterator(source, decoder)
    for record in records:

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for streamcat, version 0.2.1
Filename, size File type Python version Upload date Hashes
Filename, size streamcat-0.2.1-py2.py3-none-any.whl (3.7 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size streamcat-0.2.1.tar.gz (4.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page