Name | pipeit JSON |
Version |
0.3.3
JSON |
| download |
home_page | https://github.com/GoodManWEN/pipeit |
Summary | Syntax suger for python's functional programming as Unix pipes. - GoodManWEN/pipeit |
upload_time | 2024-02-17 09:19:24 |
maintainer | |
docs_url | None |
author | WEN |
requires_python | >=3.6 |
license | |
keywords |
pipeit
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# pipeit
[![fury](https://badge.fury.io/py/pipeit.svg)](https://badge.fury.io/py/pipeit)
[![licence](https://img.shields.io/github/license/GoodManWEN/pipeit)](https://github.com/GoodManWEN/pipeit/blob/master/LICENSE)
[![pyversions](https://img.shields.io/pypi/pyversions/pipeit.svg)](https://pypi.org/project/pipeit/)
[![Publish](https://github.com/GoodManWEN/pipeit/workflows/Publish/badge.svg)](https://github.com/GoodManWEN/pipeit/actions?query=workflow:Publish)
[![Build](https://github.com/GoodManWEN/pipeit/workflows/Build/badge.svg)](https://github.com/GoodManWEN/pipeit/actions?query=workflow:Build)
This is a super simple wrapper , let's use python functional programming like Unix pipe!
Inspired by [abersheeran/only-pipe](https://github.com/abersheeran/only-pipe) , [czheo/syntax_sugar_python](https://github.com/czheo/syntax_sugar_python) , [pipetools](https://pypi.org/project/pipetools/)
## Install
pip install pipeit
## Usage
- Statements start with `PIPE` and end with `END` **OR** you can even ellipsis them.
- There're only two objects(`PIPE` & `END`) and three types(`Filter` ,`Map` & `Reduce`) in namespace, so feel free to use `from pipeit import *`.
- Convert filter into tuple or capital the first letter, e.g. `map(lambda x:x + 1) => (map , lambda x:x + 1)` or `Map(lambda x:x + 1)` , however **DO NOT MIX USE THEM**.
- It'll be 10% ~ 20% faster using the original python functional way than using these wrappers.
v0.2.0 Update:
- Simple code timing means
v0.3.0 Update:
- Easier reading and writing operations
## Example
**Basic useage**:
```Python
>>> from pipit import PIPE , END , Map , Filter , Reduce
>>> data = PIPE | range(10) | (map , lambda x:x + 1) | (map , str) | list | END
>>> data
['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
# (map , lambda x:x + 1) equals to Map(lambda x:x + 1)
>>> func = lambda x: PIPE | range(x) | Map(lambda x:x + 1) | Map(str) | list | END
>>> func(10)
['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']
```
Or you may want a more easy use.
```Python
>>> range(10) | Filter(lambda x:x<5) | list
[0, 1, 2, 3, 4]
>>> for _ in range(3) | Map(str):
print(repr(_))
'0'
'1'
'2'
```
**Code timer updated in version 0.2.0**, you can easily detect the execution time of code blocks or statements.
```Python
from pipeit import *
from functools import reduce
foo = list(range(100))
for _ in timeit(1e6): # which means loop for 1m times
bar = foo | Filter(lambda x: x%3) | Map(lambda x: 10*x) | Reduce(lambda x, y: x+y) | int
with timeit(): # a handwritten for loop is required under context manager mode
for _ in range(int(1e6)):
bar = reduce(lambda x, y: x+y, map(lambda x: 10*x, filter(lambda x: x%3, foo)))
# output:
# [line 5][approximate] time cost / loop: 9.8967234μs
# [line 8][exact] time cost: 7.0519098s
```
**Better IO functions are updated in version 0.3.0**. If you hate typing encoding="utf-8" over and over again, believe me, you'll love them.
Use simple `Read()`/`Write()`/`ReadB()`/`WriteB()` functions instead of the default practice of `with open()`. You can specify the encoding format, but they are specified as `utf-8` by default. Another advantage of doing this is that you no longer need to worry about accidentally emptying the file by not changing 'w' to 'r'.
```Python
from pipeit import *
import json
#
Write("a.txt", "Hello World!")
WriteB("b.json", "[1, 2, 3]".encode("utf-8"))
assert Read("a.txt") == "Hello World!"
assert ReadB("b.txt") == b"[1, 2, 3]"
```
Similarly, you can use pipes to send data to them, or pipes to receive data from them.
```Python
# OR
"[1, 2, 3]".encode("utf-8") | WriteB("b.json")
# another typical scenario is to cache data to hard disk and read it back again
html_a = "abc" # requests.get("https://a.example.com").text
html_b = "123" # ...
htmls = {"html_a": html_a, "html_b": html_b}
json.dumps(htmls) | Write("htmls.json")
#
htmls = Read("htmls.json") | json.loads
html_a, html_b = htmls.values()
```
`>>` and `|` operands are functionally identical while doing IO.
```
"Hello World!" >> Write("a.txt")
text = Read("a.txt") >> str
assert text == "Hello World!"
```
Raw data
{
"_id": null,
"home_page": "https://github.com/GoodManWEN/pipeit",
"name": "pipeit",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "pipeit",
"author": "WEN",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/9a/ab/2875600f2df7f5b57b6ba9c400fa108f1f1b55940fbca54a00000509b1d3/pipeit-0.3.3.tar.gz",
"platform": null,
"description": "# pipeit\n[![fury](https://badge.fury.io/py/pipeit.svg)](https://badge.fury.io/py/pipeit)\n[![licence](https://img.shields.io/github/license/GoodManWEN/pipeit)](https://github.com/GoodManWEN/pipeit/blob/master/LICENSE)\n[![pyversions](https://img.shields.io/pypi/pyversions/pipeit.svg)](https://pypi.org/project/pipeit/)\n[![Publish](https://github.com/GoodManWEN/pipeit/workflows/Publish/badge.svg)](https://github.com/GoodManWEN/pipeit/actions?query=workflow:Publish)\n[![Build](https://github.com/GoodManWEN/pipeit/workflows/Build/badge.svg)](https://github.com/GoodManWEN/pipeit/actions?query=workflow:Build)\n\nThis is a super simple wrapper , let's use python functional programming like Unix pipe!\n\nInspired by [abersheeran/only-pipe](https://github.com/abersheeran/only-pipe) , [czheo/syntax_sugar_python](https://github.com/czheo/syntax_sugar_python) , [pipetools](https://pypi.org/project/pipetools/)\n\n## Install\n\n pip install pipeit\n\n## Usage\n- Statements start with `PIPE` and end with `END` **OR** you can even ellipsis them.\n- There're only two objects(`PIPE` & `END`) and three types(`Filter` ,`Map` & `Reduce`) in namespace, so feel free to use `from pipeit import *`.\n- Convert filter into tuple or capital the first letter, e.g. `map(lambda x:x + 1) => (map , lambda x:x + 1)` or `Map(lambda x:x + 1)` , however **DO NOT MIX USE THEM**.\n- It'll be 10% ~ 20% faster using the original python functional way than using these wrappers.\n\nv0.2.0 Update:\n- Simple code timing means\n\nv0.3.0 Update:\n- Easier reading and writing operations\n\n## Example\n**Basic useage**: \n```Python\n>>> from pipit import PIPE , END , Map , Filter , Reduce\n\n>>> data = PIPE | range(10) | (map , lambda x:x + 1) | (map , str) | list | END\n>>> data\n['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']\n\n# (map , lambda x:x + 1) equals to Map(lambda x:x + 1)\n>>> func = lambda x: PIPE | range(x) | Map(lambda x:x + 1) | Map(str) | list | END\n>>> func(10)\n['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']\n```\n\nOr you may want a more easy use.\n```Python\n>>> range(10) | Filter(lambda x:x<5) | list\n[0, 1, 2, 3, 4]\n\n>>> for _ in range(3) | Map(str):\n print(repr(_))\n\n\n'0'\n'1'\n'2'\n```\n\n**Code timer updated in version 0.2.0**, you can easily detect the execution time of code blocks or statements.\n```Python\nfrom pipeit import *\nfrom functools import reduce\n\nfoo = list(range(100))\nfor _ in timeit(1e6): # which means loop for 1m times\n bar = foo | Filter(lambda x: x%3) | Map(lambda x: 10*x) | Reduce(lambda x, y: x+y) | int\n\nwith timeit(): # a handwritten for loop is required under context manager mode\n for _ in range(int(1e6)):\n bar = reduce(lambda x, y: x+y, map(lambda x: 10*x, filter(lambda x: x%3, foo)))\n\n# output: \n# [line 5][approximate] time cost / loop: 9.8967234\u03bcs\n# [line 8][exact] time cost: 7.0519098s \n```\n\n**Better IO functions are updated in version 0.3.0**. If you hate typing encoding=\"utf-8\" over and over again, believe me, you'll love them.\n\nUse simple `Read()`/`Write()`/`ReadB()`/`WriteB()` functions instead of the default practice of `with open()`. You can specify the encoding format, but they are specified as `utf-8` by default. Another advantage of doing this is that you no longer need to worry about accidentally emptying the file by not changing 'w' to 'r'.\n\n```Python\nfrom pipeit import *\nimport json\n\n# \nWrite(\"a.txt\", \"Hello World!\")\nWriteB(\"b.json\", \"[1, 2, 3]\".encode(\"utf-8\"))\nassert Read(\"a.txt\") == \"Hello World!\"\nassert ReadB(\"b.txt\") == b\"[1, 2, 3]\"\n```\nSimilarly, you can use pipes to send data to them, or pipes to receive data from them.\n```Python\n# OR\n\"[1, 2, 3]\".encode(\"utf-8\") | WriteB(\"b.json\")\n\n# another typical scenario is to cache data to hard disk and read it back again\nhtml_a = \"abc\" # requests.get(\"https://a.example.com\").text\nhtml_b = \"123\" # ...\nhtmls = {\"html_a\": html_a, \"html_b\": html_b}\njson.dumps(htmls) | Write(\"htmls.json\")\n# \nhtmls = Read(\"htmls.json\") | json.loads\nhtml_a, html_b = htmls.values()\n```\n`>>` and `|` operands are functionally identical while doing IO.\n```\n\"Hello World!\" >> Write(\"a.txt\")\ntext = Read(\"a.txt\") >> str\nassert text == \"Hello World!\"\n```\n\n\n",
"bugtrack_url": null,
"license": "",
"summary": "Syntax suger for python's functional programming as Unix pipes. - GoodManWEN/pipeit",
"version": "0.3.3",
"project_urls": {
"Homepage": "https://github.com/GoodManWEN/pipeit"
},
"split_keywords": [
"pipeit"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "2f7aae36fcdabbfb435072d2cc8be87fe711615a18fb867b039b9ad67464b15c",
"md5": "caad22421c76626d1adefe01e842b78a",
"sha256": "c8d70a3f00419bb2ab4c143a7a4d8bd18a69d8a033dcbeffe5c28da055c24fae"
},
"downloads": -1,
"filename": "pipeit-0.3.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "caad22421c76626d1adefe01e842b78a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 15126,
"upload_time": "2024-02-17T09:18:44",
"upload_time_iso_8601": "2024-02-17T09:18:44.914708Z",
"url": "https://files.pythonhosted.org/packages/2f/7a/ae36fcdabbfb435072d2cc8be87fe711615a18fb867b039b9ad67464b15c/pipeit-0.3.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9aab2875600f2df7f5b57b6ba9c400fa108f1f1b55940fbca54a00000509b1d3",
"md5": "dd4e2d566de67fb449e2979baee010d8",
"sha256": "519d71c817b43b3415c5d93a5a72cba05e629dc3f9370f72b17ecd4d1a5f568d"
},
"downloads": -1,
"filename": "pipeit-0.3.3.tar.gz",
"has_sig": false,
"md5_digest": "dd4e2d566de67fb449e2979baee010d8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 14731,
"upload_time": "2024-02-17T09:19:24",
"upload_time_iso_8601": "2024-02-17T09:19:24.109656Z",
"url": "https://files.pythonhosted.org/packages/9a/ab/2875600f2df7f5b57b6ba9c400fa108f1f1b55940fbca54a00000509b1d3/pipeit-0.3.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-17 09:19:24",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "GoodManWEN",
"github_project": "pipeit",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "pipeit"
}