Skip to main content

Coverage badge Documentation Status DOI

eotransform

Defines the basic transform protocol to be used in the streamed source to sink concept. Also provides some generic transformer implementations such as Compose or Result.

What can I use eotransform for?

The eotransform package defines Source, Transform, and Sink protocols, to facilitate the creation of modularised processing pipelines. Adhering to a common contract, makes it easier to mix and match processing blocks, allowing for better code reusage, and more flexible pipelines. We also provide a streamed_process function, which you can use for I/O hiding when implementing these protocols. The package also provides some common transformations, and sinks like Compose or Result.

Getting Started

Installation

pip install eotransform

Examples

Transformer protocol

This example shows how to implement the Transformer protocol for a simple multiplication:

class Multiply(Transformer[int, int]):
    def __init__(self, factor: int):
        self.factor = factor

    def __call__(self, x: int) -> int:
        return x * self.factor

snippet source | anchor

Sink protocol

This code snippet illustrates how to implement the Sink protocol, using a simple accumulation example:

class AccumulatingSink(Sink[int]):
    def __init__(self):
        self.result = 0

    def __call__(self, x: int) -> None:
        self.result += x

snippet source | anchor

Streamed pipeline using the "Result" pattern

In the following example we show how to combine ApplyToOkResult and SinkUnwrapped to process data in a streamed fashion with proper error handling across thread boundaries.

def a_data_source():
    for i in range(4):
        if i == 1:
            yield Result.error(RuntimeError("A runtime error occured!"))
        else:
            yield Result.ok(i)

accumulated = AccumulatingSink()
sink = SinkUnwrapped(accumulated, ignore_exceptions={RuntimeError})
with ThreadPoolExecutor(max_workers=3) as ex:
    streamed_process(a_data_source(), ApplyToOkResult(Multiply(2)), sink, ex)

assert accumulated.result == 10

snippet source | anchor

Streaming

The following briefly describes the concept of streaming, and how it can be used to hide I/O processes.

The most straightforward way to process data is to first load it and then process it:

serial process

This has the advantage of being simple to implement and maintain, as you don't need to be concerned with issues of parallelism.

For many cases this will work sufficiently well, however, it can stall your processing pipeline because it needs to wait for data to be fetched. Often an easy way to increase throughput, is to interleave the I/O or data fetching with processing chunks:

streamed process

With this streaming process you can utilise resources more effectively.

Support & Documentation

Dependencies

eotransform requires Python 3.8 and has these dependencies:

more-itertools

snippet source | anchor

Citation

If you find this repository useful, please consider giving it a star or a citation:

@software{raml_bernhard_2023_8002789,
  author       = {Raml, Bernhard},
  title        = {eotransform},
  month        = jun,
  year         = 2023,
  publisher    = {Zenodo},
  version      = {1.8.2},
  doi          = {10.5281/zenodo.8002789},
  url          = {https://doi.org/10.5281/zenodo.8002789}
}

Metadata

Release files for eotransform 1.8.4

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

Source distribution (sdist)

Source distribution for eotransform 1.8.4
File Size Uploaded Provenance Actions
eotransform-1.8.4.tar.gz 18.1 kB Without provenance Details for eotransform-1.8.4.tar.gz

Built distribution (wheel)

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

Total release size: 36.0 kB

Release files / eotransform-1.8.4.tar.gz

Download URL eotransform-1.8.4.tar.gz
Size 18.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5a2b7d967885ee822640033c552e2f47d496b1f683ed35767c6412794532785c
BLAKE2b-256 checksum
How to use checksums
a623ea1b1d39d24cd2110ed6fe144df6b490ac13d775bfe1fdf435fd84c86a71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.1

Release files / eotransform-1.8.4-py3-none-any.whl

Download URL eotransform-1.8.4-py3-none-any.whl
Size 17.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b459f69e9ce68f4a623d168c7f7f035324d2d79bed4d7926d3c3953c1fe14194
BLAKE2b-256 checksum
How to use checksums
ec2dc90e1804b107977c10b8fd168d555fca43fdb543c47596b76fdd8f87b416
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.1

Security for eotransform 1.8.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.

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