{"id":20815188,"url":"https://github.com/hoishing/pipable","last_synced_at":"2026-01-24T02:05:59.595Z","repository":{"id":65681662,"uuid":"595556459","full_name":"hoishing/pipable","owner":"hoishing","description":"pipe operation in python","archived":false,"fork":false,"pushed_at":"2024-10-05T03:11:10.000Z","size":1424,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T12:09:59.542Z","etag":null,"topics":["fp","functional-programming","pipe","pipleline"],"latest_commit_sha":null,"homepage":"https://hoishing.github.io/pipable","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/hoishing.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,"publiccode":null,"codemeta":null}},"created_at":"2023-01-31T10:27:45.000Z","updated_at":"2024-10-05T03:10:34.000Z","dependencies_parsed_at":null,"dependency_job_id":"43d15162-a1e5-450e-93ad-ad3c0be7a3b0","html_url":"https://github.com/hoishing/pipable","commit_stats":{"total_commits":20,"total_committers":1,"mean_commits":20.0,"dds":0.0,"last_synced_commit":"247cbec0470e28722e6f86ba4bf41474dbef2cab"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoishing%2Fpipable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoishing%2Fpipable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoishing%2Fpipable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hoishing%2Fpipable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hoishing","download_url":"https://codeload.github.com/hoishing/pipable/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252873949,"owners_count":21817714,"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":["fp","functional-programming","pipe","pipleline"],"created_at":"2024-11-17T21:19:54.238Z","updated_at":"2026-01-24T02:05:59.590Z","avatar_url":"https://github.com/hoishing.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pipable\n\n[![ci-badge]][ci-url] [![pypi-badge]][pypi-url] [![MIT-badge]][MIT-url] [![black-badge]][black-url]\n\n\u003e pipe operation in python\n\n---\n\n\u003e [!NOTE]\n\u003e This repository has been archived. While being able to chain function calls with a pipe operator looks handy and more \"functional\", the trade-off of breaking normal Python coding style outweighed the benefits of the syntactic sugar, especially when working with LLMs. Keeping to the conventional way of writing code is friendlier to LLMs and human readers, and thus enhances productivity.\n\n## Quick Start\n\n### Create the Pipe Object\n\n- instantiate with the `Pipe` class\n\n```python\nfrom pipable import Pipe\n\nlist = Pipe(list)\n\"abc\" | list    # [\"a\", \"b\", \"c\"]\n```\n\n#### Pipe Object is Partial with Infix Operator\n\n- at the core Pipe create partial function while overriding it's `|` operator\n- instantiate Pipe object like the built-in `functools.partial`\n- preceding output will be assigned to the **last positional** argument of the Pipe object\n\n```python\nsquare = Pipe(pow, exp=2)\n3 | square    # 9\n```\n\nSince that Pipe appends preceding output to the last positional argument,\nassigning 1st argument with keyword will raise exception.\nThis behave the same as `functools.partial`\n\n```python\nbase2 = Pipe(pow, 2)  # positional arg ok\n3 | base2    # 8\n\nbase2 = Pipe(pow, base=2)  # keyword arg don't\n3 | base2    # raise!!\n```\n\n### Using Decorator\n\n- `@Pipe` decorator transforms function into Pipe object\n- preceding output will be assigned to the last positional argument\n- instantiate Pipe decorated function similar to creating partial\n\n```python\n# only one argument\n@Pipe\ndef hi(name: str) -\u003e str:\n  return f\"hi {name}\"\n\n\"May\" | hi    # \"hi May\"\n\n\n# multiple arguments\n@Pipe\ndef power(base: int, exp: int) -\u003e int:\n  return base ** exp\n\n# instantiate Pipe obj by partially calling the function\n2 | power(3)        # 9, note we need to use positional argument here\n2 | power(exp=3)    # 8, subsequent arguments can use keyword\n\n# assign the 1st argument with keyword will raise exception\n2 | power(base=3)    # raise !!\n```\n\n### Passing Variable Length Arguments\n\n- use `\u003e\u003e` operator to pass-in variable length arguments\n\n```python\n@Pipe\ndef kebab(*args):\n    return \"-\".join(args)\n\n[\"a\", \"b\"] \u003e\u003e kebab   # \"a-b\"\n```\n\n- use `\u003c\u003c` operator to pass variable length keyword arguments\n\n```python\n@Pipe\ndef concat(**kwargs):\n    return \", \".join([f\"{k}-{v}\" for k, v in kwargs.items()])\n\ndict(b=\"boy\", c=\"cat\") \u003c\u003c concat    # \"b-boy, c-cat\"\n```\n\n- refer the [docs](https://hoishing.github.io/pipable/reference) for details\n\n## Motivation\n\nPipe operation is a handy feature in functional programming. It allows us to:\n\n- write more succinct and readable code\n- create less variables\n- easily create new function by chaining other functions\n\nHowever it's still a missing feature in Python as of 2023. This package try to mimic pipe operation by overriding the bitwise-or operator, and turn any function into pipable partial.\n\nThere are packages, such as [pipe] take the similar approach. It works great with iterables, and create pipe as iterator, ie. open pipe). However, I simply want to take preceding expression as an input argument of the current function then execute it, ie. close pipe. It leads to the creation of this package.\n\n## FAQ\n\nHow can I assign value to the first argument?\n  \nuse a wrapper function\n\n```python\nsquare = Pipe(lambda x: pow(x, 2))\n3 | square  # 9\n```\n\n---\n\nCan I create open pipe?\n\n`Pipe` only create closed pipe, ie. execute the function after piping with the `|` operator. You may consider other solutions such as:\n\n- [pipe], which create open pipe for iterators\n- [Coconut], a python variant that embrace functional programming\n\n---\n\nCan I append the preceding output at the beginning of the argument list?\n\nPut the preceding output as the 1st argument of a wrapper function\n\n```python\n# prepend is the default behaviour\ndef kebab(*args):\n  return \"-\".join(*args)\n\n'a' | Pipe(kebab, 'b', 'c')  # 'b c a'\n\n@Pipe\ndef wrapper(first, others):\n  return kebab(first, *others)\n\n'a' | wrapper(others=['b', 'c'])  # 'a b c'\n```\n\n## Need Help?\n\n[![git-logo] github issue][github issue]\n\n[![x-logo] posts][x-post]\n\n[black-badge]: https://img.shields.io/badge/code%20style-black-000000.svg\n[black-url]: https://github.com/psf/black\n[ci-badge]: https://github.com/hoishing/pipable/actions/workflows/ci.yml/badge.svg\n[ci-url]: https://github.com/hoishing/pipable/actions/workflows/ci.yml\n[Coconut]: https://github.com/evhub/coconut\n[git-logo]: https://api.iconify.design/bi/github.svg?color=%236FD886\u0026width=20\n[github issue]: https://github.com/hoishing/pipable/issues\n[MIT-badge]: https://img.shields.io/github/license/hoishing/pipable\n[MIT-url]: https://opensource.org/licenses/MIT\n[pipe]: https://pypi.org/project/pipe\n[pypi-badge]: https://img.shields.io/pypi/v/pipable\n[pypi-url]: https://pypi.org/project/pipable/\n[x-logo]: https://api.iconify.design/ri:twitter-x-fill.svg?width=20\u0026color=DarkGray\n[x-post]: https://x.com/hoishing\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoishing%2Fpipable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhoishing%2Fpipable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhoishing%2Fpipable/lists"}