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
- 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())
- 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())
- 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)
- 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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| streamiopipe-0.1.1.tar.gz | 2.6 kB | Without provenance | Details for streamiopipe-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| streamiopipe-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for streamiopipe-0.1.1-py3-none-any.whl |
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
|
Security for streamiopipe 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.