Name | pipestream JSON |
Version |
1.0.1
JSON |
| download |
home_page | |
Summary | A convenient way to 'pipe' a given input through a series of classes or callables |
upload_time | 2023-04-10 15:16:51 |
maintainer | |
docs_url | None |
author | |
requires_python | >=3.10 |
license | |
keywords |
pipeline
middleware
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 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:
```python
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](https://refactoring.guru/design-patterns/chain-of-responsibility).
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`.
```python
from pipestream import Pipeline
user = Pipeline
.send(user)
.through(
GenerateProfilePhoto,
ActivateSubscription,
SendWelcomeEmail
)
.via('do')
.then(lambda value: value)
```
## Install
```sh
$ pip install pipestream
```
## Running tests
```sh
$ pytest tests/
```
This package is inspired by [Laravel's Pipeline Helper](https://laravel.com/docs/10.x/helpers#pipeline)
Raw data
{
"_id": null,
"home_page": "",
"name": "pipestream",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": "",
"keywords": "pipeline,middleware",
"author": "",
"author_email": "Rafael Acioly <aciolyr@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/a2/5e/bf7c88f04779fca15b0f60fa02a01a283bcd88ceaae40fbbb86734417db5/pipestream-1.0.1.tar.gz",
"platform": null,
"description": "# Pipestream\n\n## Usage\n\nPipestream 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:\n\n```python\nfrom pipestream import Pipeline\n\n\ndef sum_one(value, next):\n return next(value + 1)\n\n\ndef multiply_by_two(value, next):\n return next(value * 2)\n\n\nPipeline\n .send(1)\n .through(\n sum_one,\n multiply_by_two\n )\n .then(print)\n\n# output: 4\n```\n\nAs 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](https://refactoring.guru/design-patterns/chain-of-responsibility).\n\nWhen 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.\n\nOf 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`.\n\n```python\nfrom pipestream import Pipeline\n\n\nuser = Pipeline\n .send(user)\n .through(\n GenerateProfilePhoto,\n ActivateSubscription,\n SendWelcomeEmail\n )\n .via('do')\n .then(lambda value: value)\n```\n\n## Install\n```sh\n$ pip install pipestream\n ```\n\n## Running tests\n```sh\n$ pytest tests/\n```\n\nThis package is inspired by [Laravel's Pipeline Helper](https://laravel.com/docs/10.x/helpers#pipeline)\n",
"bugtrack_url": null,
"license": "",
"summary": "A convenient way to 'pipe' a given input through a series of classes or callables",
"version": "1.0.1",
"split_keywords": [
"pipeline",
"middleware"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "afcd3659ec35f00aa9a323054584601231e7acf744b3fca98814f045aaf9351b",
"md5": "083d5324ff96ba63945ac15513b3e5e0",
"sha256": "e6e27ed0ca1450606e7d26bdd9012ad45872cac1e339102c1d64f99ab62183ec"
},
"downloads": -1,
"filename": "pipestream-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "083d5324ff96ba63945ac15513b3e5e0",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.10",
"size": 3890,
"upload_time": "2023-04-10T15:16:49",
"upload_time_iso_8601": "2023-04-10T15:16:49.491294Z",
"url": "https://files.pythonhosted.org/packages/af/cd/3659ec35f00aa9a323054584601231e7acf744b3fca98814f045aaf9351b/pipestream-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a25ebf7c88f04779fca15b0f60fa02a01a283bcd88ceaae40fbbb86734417db5",
"md5": "a1b127859332312f4c3f43b5d09f51ce",
"sha256": "51a2d004f40e820f811770790ee049e1623946393334701c6781b25c07424510"
},
"downloads": -1,
"filename": "pipestream-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "a1b127859332312f4c3f43b5d09f51ce",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 3851,
"upload_time": "2023-04-10T15:16:51",
"upload_time_iso_8601": "2023-04-10T15:16:51.740526Z",
"url": "https://files.pythonhosted.org/packages/a2/5e/bf7c88f04779fca15b0f60fa02a01a283bcd88ceaae40fbbb86734417db5/pipestream-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-10 15:16:51",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "pipestream"
}