Pipeline Functions
Pipeline Functions is a simple utility for calling functions in "pipelines", i.e. where the output from one function is automatically the input for the next. Here's an example showing how this works:
>>> from pipeline_func import f, X
>>> a = [3, 4, 2, 1, 0]
>>> b = [2, 1, 4, 0, 3]
>>> a | f(zip, b) | f(map, min, X) | f(filter, bool, X) | f(sorted)
[1, 2, 2]
To briefly explain, we start with two random lists of integers. We then find the smaller value in each position, discard any zeros, and sort whatever remains. Contrast the easily-readable pipeline syntax to what would be necessary without it:
>>> sorted(filter(bool, map(min, zip(a, b))))
[1, 2, 2]
Documentation
This library provides a single function, named f(). The purpose of f() is
to wrap another function such that it can be called as part of a pipeline.
Below is the call signature for f():
f(func: Callable[..., Any], /, *args: Any, **kwargs: Any)
The first argument to f() must be a function. The remaining arguments can be
arbitrary positional and/or keyword arguments. f() produces a wrapped version
of the given function which can subsequently be called using the | operator
as shown above. By default, the value from the left-hand side of the operator
will be the first argument to the function. Any extra arguments provided to f
will be added after.
If it's not convenient for the incoming value to be the first argument to the
wrapped function, you can use the X object to put the arguments in any order
you want. Think of X as a placeholder that will be replaced by the value
from the previous step in the pipeline. X can be either a positional or a
keyword argument, and can be used for multiple arguments at the same time. You
can also use attribute access syntax (e.g. X.my_attr), item lookup syntax
(e.g. X[key]), function invocation syntax (e.g. X(arg1, arg2)), or any
combination of the above (e.g. X.my_method()[0]) to easily extract
information from the input value.
To make this more concrete, here are some examples showing how f() can be
used to call some common functions:
| Pipeline | Equivalent to | Result |
|---|---|---|
[1, 2] | f(min) |
min([1, 2]) |
1 |
[1, 2] | f(zip, [3, 4]) |
zip([1, 2], [3, 4]) |
[[1, 3], [2, 4]] |
[1, 2] | f(sorted, reverse=True) |
sorted([1, 2], reverse=True) |
[2, 1] |
[1, 2] | f(map, str, X) |
map([1, 2], str) |
['1', '2'] |
This library only works if each pipeline function has exactly one input and one
output. It also requires that the initial input object does not implement the
left | operator for pipeline_func.PipelineFunc objects. This should be true
for any well-behaved object, though.
Metadata
Release files for pipeline-func 1.0.0
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 |
|---|---|---|---|---|
| pipeline_func-1.0.0.tar.gz | 3.4 kB | Without provenance | Details for pipeline_func-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pipeline_func-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for pipeline_func-1.0.0-py3-none-any.whl |
Total release size: 6.9 kB
Release files / pipeline_func-1.0.0.tar.gz
| Download URL | pipeline_func-1.0.0.tar.gz |
|---|---|
| Size | 3.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
73d19ea19434c23233eed744bca7215f9c8562da9afa9f82dad71696a13e799a
|
|
BLAKE2b-256 checksum How to use checksums |
bdc3025d7414ca32ed423ac2b96f37c3047f9343b23280f34a474577280e74d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Release files / pipeline_func-1.0.0-py3-none-any.whl
| Download URL | pipeline_func-1.0.0-py3-none-any.whl |
|---|---|
| Size | 3.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
09bf80c63e52734d349d2241f14d0432ce47d14ca03b76f924cacd0ba5a16198
|
|
BLAKE2b-256 checksum How to use checksums |
0687d1e43c14588d5f87b9d4870daedbe45e3e3f1ced9737b3add15b0c38a5b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.0.0 CPython/3.12.3
|
Security for pipeline-func 1.0.0
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.