iterable-io
iterable-io is a small Python library that provides an adapter so that it's possible to read from
iterable objects in the same way as
file-like objects.
It is primarily useful as "glue" between two incompatible interfaces. As an example, in the case
where one interface expects a file-like object to call .read() on, and the other only provides a
generator of bytes.
One way to solve this issue would be to write all the bytes in the generator to a temporary file, then provide that file instead, but if the generator produces a large amount of data then this is both slow to start, and resource-intensive.
This library allows streaming data between these two incompatible interfaces so as data is requested
by .read(), it's pulled from the iterable. This keeps resource usage low and removes the startup
delay.
Installation
pip install iterable-io
Documentation
The functionality of this library is accessed via a single function: open_iterable().
open_iterable() is designed to work the same way as the builtin open(), except that it takes an
iterable to "open" instead of a file. For example, it can open the iterable in binary or text mode,
has options for buffering, encoding, etc. See the docstring of open_iterable for more detailed
documentation.
Simple examples
The following examples should be enough to understand in which cases open_iterable() would be
useful and get a high-level understanding of how to use it:
Read bytes from a generator of bytes:
gen = generate_bytes()
# adapt the generator to a file-like object in binary mode
# (fp.read() will return bytes)
fp = open_iterable(gen, "rb")
while chunk := fp.read(4096):
process_chunk(chunk)
Read lines of text from a generator of bytes:
gen = generate_bytes()
# adapt the generator to a file-like object in text mode
# (fp.read() will return a string, fp.readline is also available)
fp = open_iterable(gen, "rt", encoding="utf-8")
for line in fp:
process_line_of_text(line)
Tests
This package contains tests. To run them, install pytest (pip install pytest) and run
py.test in the project directory.
License
Licensed under the GNU LGPLv3.
Metadata
Release files for iterable-io 1.0.4
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 |
|---|---|---|---|---|
| iterable_io-1.0.4.tar.gz | 5.6 kB | Without provenance | Details for iterable_io-1.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| iterable_io-1.0.4-py3-none-any.whl | Python 3 | none | any | Details for iterable_io-1.0.4-py3-none-any.whl |
Total release size: 10.3 kB
Release files / iterable_io-1.0.4.tar.gz
| Download URL | iterable_io-1.0.4.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
63b5b394aedbc61b4409a0d213130a4d153c602d1eac9dcff860a43ae0340405
|
|
BLAKE2b-256 checksum How to use checksums |
0fc5c3578d4ebc1f0e80c1a321b9f81a74c4486a6ad48e2a3dd1d228e3ba6199
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / iterable_io-1.0.4-py3-none-any.whl
| Download URL | iterable_io-1.0.4-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7d7104b69e499bcdad856e623bbc0feb0970eae5416b2b49be8b822ff4a37347
|
|
BLAKE2b-256 checksum How to use checksums |
592866a098e4c0428d1dfd0a30f8fe1ddfeb4a0d9472c8b117169e77b57a5f14
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Security for iterable-io 1.0.4
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.