Skip to main content

StreamIOPipe

A library that allows to process streams using simple user defined functions in a sequence as if you were using pipes.

Installation

pip install streamoipipe

Examples

  1. Read text from a StringIO and add line numbers
from streamiopipe import *
import sys
import io

@stringiopipe
def add_lineno(outstream,instream):
    """ prepend line with an auto increment
    """
    lineno = 1

    for line in instream:
        outstream.write(f"{lineno:02d}:{line}")
        lineno+=1


text_in = io.StringIO("""January
February
March
April""")

text_out = io.StringIO()
with StreamIOPipe(filein=text_in,fileout=text_out,text=True) as sp:
    sp.run(add_lineno)

print(text_out.getvalue())
  1. Read text from a StringIO and add line numbers and then remove them
from streamiopipe import *
import sys
import io

@stringiopipe
def add_lineno(outstream,instream):
    """ prepend line with an auto increment
    """
    lineno = 1

    for line in instream:
        outstream.write(f"{lineno:02d}:{line}")
        lineno+=1

@stringiopipe
def remove_lineno(outstream,instream):
    """ prepend line with an auto increment
    """

    for line in instream:
        outstream.write(line[3:])



text_in = io.StringIO("""January
February
March
April""")

text_out = io.StringIO()
with StreamIOPipe(filein=text_in,fileout=text_out,text=True) as sp:
    sp.iterate([(add_lineno,),(remove_lineno,)])

print(text_out.getvalue())
  1. XOR a binary file from stdin and write to stdout
from streamiopipe import *
import sys
import io
import struct

@byteiopipe
def xor(outstream,instream,value=0xFA):
    """ Iterate all bytes and xor them with value
    """
    for block in iter(lambda: instream.read(1), b''):
        byte = block[0]
        out = byte ^ value
        outstream.write(struct.pack("=B",out))

# read from stdin, xor and write to stdout
with StreamIOPipe(text=False) as sp:
    sp.run(xor,value=0xBC)
  1. XOR and Rotate Left a file from stdin and write to stdout
from streamiopipe import *
import sys
import io
import struct

@byteiopipe
def xor(outstream,instream,value=0xAA):
    """ Iterate all bytes and xor them with value
    """
    for block in iter(lambda: instream.read(1), b''):
        byte = block[0]
        out = byte ^ value
        outstream.write(struct.pack("=B",out))

@byteiopipe
def rol(outstream,instream,value=1):
    """ Iterate all bytes and rotate left by value
    """
    div,mod = divmod(value,8)
    rest = 8 - mod
    for block in iter(lambda: instream.read(1), b''):
        byte = block[0]
        out = 255 & (byte << mod | byte >> rest)
        outstream.write(struct.pack("=B",out))

# read from stdin, xor and write to stdout
with StreamIOPipe(text=False) as sp:
    sp.iterate([(xor,{'value':0xD0}), (rol,{'value':4})])

Metadata

Release files for streamiopipe 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for streamiopipe 0.1.1
File Size Uploaded
streamiopipe-0.1.1.tar.gz 2.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for streamiopipe 0.1.1
File Interpreter ABI Platform
streamiopipe-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 5.7 kB

Release files / streamiopipe-0.1.1.tar.gz

Download URL streamiopipe-0.1.1.tar.gz
Size 2.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9c5ffc76cf22d0a4e6aced671e2bc91e47596612ac9872d9fd7295543aa77060
BLAKE2b-256 checksum
How to use checksums
c0b50d63a0cb079aafb2536b7285fea5e47891d22ccba4d9babceca7b410caed
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.7

Release files / streamiopipe-0.1.1-py3-none-any.whl

Download URL streamiopipe-0.1.1-py3-none-any.whl
Size 3.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
17fbbc6b3bd98f012e5dddddc3a6888fb749e5e6e63afa50af576fe32c56f98f
BLAKE2b-256 checksum
How to use checksums
d16f6df83a4b1e6aa3cc9f1eb7f60b8ea320e3508a75060918b100d829e70a74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.11.7

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page