Building simple pipelines, simply.
Project description
lined
Building simple pipelines, simply.
A really simple example:
>>> p = Pipeline(sum, str)
>>> p([2, 3])
'5'
A still quite simple example:
>>> def first(a, b=1):
... return a * b
>>>
>>> def last(c) -> float:
... return c + 10
>>>
>>> f = Pipeline(first, last)
>>>
>>> assert f(2) == 12
>>> assert f(2, 10) == 30
Let's check out the signature of f:
>>> from inspect import signature
>>>
>>> assert str(signature(f)) == '(a, b=1) -> float'
>>> assert signature(f).parameters == signature(first).parameters
>>> assert signature(f).return_annotation == signature(last).return_annotation == float
Border case: One function only
>>> same_as_first = Pipeline(first)
>>> assert same_as_first(42) == first(42)
More?
string and dot digraph representations
Pipeline's string representation (__repr__
) and how it deals with callables that don't have a __name__
(hint: it makes one up):
from lined.base import Pipeline
from functools import partial
pipe = Pipeline(sum, np.log, str, print, partial(map, str), name='some_name')
pipe
Pipeline(sum, log, str, print, unnamed_func_001, name='some_name')
If you have graphviz installed, you can also do this:
pipe.dot_digraph()
And if you don't, but have some other dot language interpreter, you can just get the body (and fiddle with it):
print('\n'.join(pipe.dot_digraph_body()))
rankdir="LR"
sum [shape="box"]
log [shape="box"]
str [shape="box"]
print [shape="box"]
unnamed_func_001 [shape="box"]
sum -> log
log -> str
str -> print
print -> unnamed_func_001
Optionally, a pipeline can have an input_name
and/or an output_name
.
These will be used in the string representation and the dot digraph.
pipe = Pipeline(sum, np.log, str, print, partial(map, str), input_name='x', output_name='y')
str(pipe)
"Pipeline(sum, log, str, print, unnamed_func_001, name='some_name')"
pipe.dot_digraph()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
lined-0.0.6.tar.gz
(2.4 kB
view hashes)
Built Distribution
lined-0.0.6-py3-none-any.whl
(2.8 kB
view hashes)