Pipestream
Usage
Pipestream provides a convenient way to "pipe" a given input through a series of classes or callable, giving each class the opportunity to inspect or modify the input and invoke the next callable in the pipeline:
from pipestream import Pipeline
def sum_one(value, next):
return next(value + 1)
def multiply_by_two(value, next):
return next(value * 2)
Pipeline
.send(1)
.through(
sum_one,
multiply_by_two
)
.then(print)
# output: 4
As you can see, each invokable class or closure in the pipeline is provided the input and a next closure. Invoking the next closure will invoke the next callable in the pipeline. As you may have noticed, this is very similar to middleware and chain of responsability pattern.
When the last callable in the pipeline invokes the next closure, the callable provided to the then method will be invoked. Typically, this callable will simply return the given input.
Of course, as discussed previously, you are not limited to providing functions to your pipeline. You may also provide classes with common method's between them. If a class is provided, the class method will be accessed by python std method getattr.
from pipestream import Pipeline
user = Pipeline
.send(user)
.through(
GenerateProfilePhoto,
ActivateSubscription,
SendWelcomeEmail
)
.via('do')
.then(lambda value: value)
Install
$ pip install pipestream
Running tests
$ pytest tests/
This package is inspired by Laravel's Pipeline Helper
Release files for pipestream 1.0.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 | |
|---|---|---|---|
| pipestream-1.0.1.tar.gz | 3.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pipestream-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.7 kB
Release files / pipestream-1.0.1.tar.gz
| Download URL | pipestream-1.0.1.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
51a2d004f40e820f811770790ee049e1623946393334701c6781b25c07424510
|
|
BLAKE2b-256 checksum How to use checksums |
a25ebf7c88f04779fca15b0f60fa02a01a283bcd88ceaae40fbbb86734417db5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Release files / pipestream-1.0.1-py3-none-any.whl
| Download URL | pipestream-1.0.1-py3-none-any.whl |
|---|---|
| Size | 3.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e6e27ed0ca1450606e7d26bdd9012ad45872cac1e339102c1d64f99ab62183ec
|
|
BLAKE2b-256 checksum How to use checksums |
afcd3659ec35f00aa9a323054584601231e7acf744b3fca98814f045aaf9351b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|