{"id":18004742,"url":"https://github.com/goodmanwen/pipeit","last_synced_at":"2025-03-26T10:31:41.806Z","repository":{"id":42722067,"uuid":"329163496","full_name":"GoodManWEN/pipeit","owner":"GoodManWEN","description":"Syntax suger for python's functional programming as Unix pipes.","archived":false,"fork":false,"pushed_at":"2024-03-15T17:09:28.000Z","size":95,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-09-19T00:25:07.632Z","etag":null,"topics":["functional-programming","pipe"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GoodManWEN.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-01-13T01:51:14.000Z","updated_at":"2024-02-16T12:25:48.000Z","dependencies_parsed_at":"2024-02-29T22:29:18.790Z","dependency_job_id":"661daa3e-bdd8-4af0-b599-a4e16c92206c","html_url":"https://github.com/GoodManWEN/pipeit","commit_stats":{"total_commits":35,"total_committers":1,"mean_commits":35.0,"dds":0.0,"last_synced_commit":"1633427f5417367a77862a673e5899de6a573b14"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodManWEN%2Fpipeit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodManWEN%2Fpipeit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodManWEN%2Fpipeit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoodManWEN%2Fpipeit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GoodManWEN","download_url":"https://codeload.github.com/GoodManWEN/pipeit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222138061,"owners_count":16937415,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["functional-programming","pipe"],"created_at":"2024-10-30T00:15:48.977Z","updated_at":"2024-10-30T00:15:49.522Z","avatar_url":"https://github.com/GoodManWEN.png","language":"Python","readme":"# 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` \u0026 `END`) and three types(`Filter` ,`Map` \u0026 `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) =\u003e (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\u003e\u003e\u003e from pipit import PIPE , END , Map , Filter , Reduce\n\n\u003e\u003e\u003e data = PIPE | range(10) | (map , lambda x:x + 1) | (map , str) | list | END\n\u003e\u003e\u003e 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\u003e\u003e\u003e func = lambda x: PIPE | range(x) | Map(lambda x:x + 1) | Map(str) | list | END\n\u003e\u003e\u003e 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\u003e\u003e\u003e range(10) | Filter(lambda x:x\u003c5) | list\n[0, 1, 2, 3, 4]\n\n\u003e\u003e\u003e 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μs\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`\u003e\u003e` and `|` operands are functionally identical while doing IO.\n```Python\n\"Hello World!\" \u003e\u003e Write(\"a.txt\")\ntext = Read(\"a.txt\") \u003e\u003e str\nassert text == \"Hello World!\"\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodmanwen%2Fpipeit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgoodmanwen%2Fpipeit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgoodmanwen%2Fpipeit/lists"}