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
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
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
Built Distribution
Hashes for iterable-subprocess-0.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d48ddc600ac148861c0481707596af7eb9730fff4e57c05240e5422f07cbd51 |
|
MD5 | a874d5d9508bfd8175aaf8bd1f761cb9 |
|
BLAKE2b-256 | 44e50752c8ca8883987e717bfec6188a79251c098439f6861b3ee9bdfad13a54 |
Hashes for iterable_subprocess-0.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a03a3abc3f8130cc0c83752a5ccebcfad0668ad7305872e6d66aaaa797edde78 |
|
MD5 | fd31d05a6f4c21fc51fc9ca8c3bcf948 |
|
BLAKE2b-256 | dfbf4304e9a1b60e7f47879449552976f8a627b82ec2320377214993878d1c09 |