{"id":15893417,"url":"https://github.com/multimeric/withpartial","last_synced_at":"2025-04-02T17:42:59.253Z","repository":{"id":57497111,"uuid":"421274495","full_name":"multimeric/WithPartial","owner":"multimeric","description":"A utility for functional piping in Python that allows you to access any function in any scope as a partial.","archived":false,"fork":false,"pushed_at":"2021-10-26T12:03:27.000Z","size":22,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-21T05:23:38.907Z","etag":null,"topics":["functional-programming","pipe","pipes","python"],"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/multimeric.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-10-26T04:07:44.000Z","updated_at":"2021-10-26T12:03:30.000Z","dependencies_parsed_at":"2022-09-03T23:51:09.856Z","dependency_job_id":null,"html_url":"https://github.com/multimeric/WithPartial","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multimeric%2FWithPartial","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multimeric%2FWithPartial/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multimeric%2FWithPartial/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/multimeric%2FWithPartial/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/multimeric","download_url":"https://codeload.github.com/multimeric/WithPartial/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246863831,"owners_count":20846319,"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","pipes","python"],"created_at":"2024-10-06T08:10:28.785Z","updated_at":"2025-04-02T17:42:59.231Z","avatar_url":"https://github.com/multimeric.png","language":"Python","readme":"# WithPartial\n## Introduction\n\nWithPartial is a simple utility for functional piping in Python.\nThe package exposes a context manager (used with `with`) called `PipeContext`, that allows you to access any function in any scope as a partial, meaning that it's naturally pipeable.\nHere's a contrived example from the test suite:\n\n```python\nimport numpy as np\nfrom with_partial import PartialContext\nfrom pipetools import pipe\n\nwith PartialContext() as _:\n    ret = (\n            10 \u003e pipe |\n            _.np.ones() |\n            _.np.reshape(newshape=(5, 2)) |\n            _.np.mean() |\n            _.int()\n    )\n    assert ret == 1\n```\n\nAs you can see, we were able to call both `numpy` and built-in functions on the `_` object, and it executed the pipeline similarly to say R's `magrittr` package.\n\n## Installation\n```bash\npip install with_partial\n```\n\n## Usage\nActually WithPartial doesn't provide an actual piping mechanism, but it does add a useful syntax for use with pipes.\nFor the actual piping mechanism, I suggest that you try [pipetools](https://0101.github.io/pipetools/doc/index.html), which this package is actually tested against.\n\nWithPartial provides a single class: `PipeContext`.\nThe way you use `PipeContext` is by first using it as a context manager:\n```python\nwith PipeContext() as _:\n```\n\nThen, using the return value of the context manager, which we have named `_` (but you could call it anything), you access attributes and items (using `.attr` or `[\"key\"]` or `[0]`) to locate the function you want and then you finally call it `()`, which will create the partial.\nYou can use positional and keyword arguments at this point if you need\n\nFor more usage information, refer to the [test suite](https://github.com/multimeric/WithPartial/tree/master/test).\n\n## Tests\n\nNote: you will need [poetry](https://python-poetry.org/docs/pyproject/) installed.\n\n```bash\ngit clone https://github.com/multimeric/WithPartial.git\ncd WithPartial\npoetry install --extras pipetools\npoetry run pytest test/\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmultimeric%2Fwithpartial","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmultimeric%2Fwithpartial","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmultimeric%2Fwithpartial/lists"}