Skip to main content

Communicate with a subprocess using iterables: for when data is too big to fit in memory and has to be streamed

Project description

iterable-subprocess CircleCI Test Coverage

Python utility function to communicate with a subprocess using iterables: for when data is too big to fit in memory and has to be streamed.

Data is sent to a subprocess's standard input via an iterable, and extracted via another iterable. This allows an external subprocess to be naturally placed in a chain of iterables for streaming processing.

Installation

pip install iterable-subprocess

Usage

A single function iterable_subprocess is exposed. The first parameter is the args argument passed to the Popen Constructor, and the second is an iterable whose items must be bytes instances and are sent to the subprocess's standard input.

Returned from the function is an iterable whose items are bytes instances of the processes standard output.

from iterable_subprocess import iterable_subprocess

def yield_input():
    # In a real case could read from the filesystem or the network
    yield b'first\n'
    yield b'second\n'
    yield b'third\n'

output = iterable_subprocess(['cat'], yield_input())

for chunk in output:
    print(chunk)

Project details


Download files

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

Source Distribution

iterable-subprocess-0.0.1.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iterable_subprocess-0.0.1-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file iterable-subprocess-0.0.1.tar.gz.

File metadata

  • Download URL: iterable-subprocess-0.0.1.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.8.5

File hashes

Hashes for iterable-subprocess-0.0.1.tar.gz
Algorithm Hash digest
SHA256 bd1f5b59985c6cfbf653c0444e9b199748844c0ca1d5040b56470b21709a1a96
MD5 a3f72c2e3372a2adf49d516afdd6db5e
BLAKE2b-256 c7d79074b5db340198f7ad0d9e925e8be02c000ca46065f7f4696480a98f839e

See more details on using hashes here.

File details

Details for the file iterable_subprocess-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: iterable_subprocess-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.5.0.1 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.42.0 CPython/3.8.5

File hashes

Hashes for iterable_subprocess-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 54b1f16283fbbb5d7aac0e47b662a8b0ec7f476462388d70588813dde103da3c
MD5 5203d688087d70a55fc5cc965a1b1276
BLAKE2b-256 6afea967a259831f2e7915b208c555f9daa0080b0b36ac4115ee5f51d4df0dbc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page