# parabar
Progress bars from `tqdm` for multiprocessing with `pathos` in Python.
This is similar in spirit to `tqdm_pathos` but more simplified.
## Installation
`pip install parabar`
## Usage
There is a single function `parabar.map`.
The two required arguments are the function you want to map and the iterable(s) you want to map over: `parabar.map(func, iterable)`.
If you want to iterate over multiple arguments, you should zip them: `parabar.map(func, zip(iterable1, iterable2))`.
It has two optional arguments:
- `ncpus = 1`: the number of processes for the pool
- `tqdm_kwargs = {}`: dictionary of extra arguments to pass to `tqdm`.
If the length of your iterable is `total`, you can tell `tqdm` by using `tqdm_kargs = {'total': total}`. Otherwise, `parabar.map` will convert your iterables to a list and use `len`.
You can provide other fixed positional and keywords arguments to your function that you do not want to iterate over as the reminaing position and keyword arguments: `parabar.map(func, iterable, arg1, arg2, kwarg1=None, ncpus=1)`.
## Examples
### Function of a single iterable:
```
f = lambda x: x**2
iterable = [1, 2, 3]
# Serial
y = [f(x) for x in iterable]
print(y)
# Parallel
y = parabar.map(f, iterable)
print(y)
```
### Function of a single iterable, with non-iterable args and kwargs:
```
f = lambda x, a, b = 0: x**2 * a + b
iterable = [1, 2, 3]
a = 1
b = 0
# Serial
y = [f(x, a, b = b) for x in iterable]
print(y)
# Parallel
y = parabar.map(f, iterable, a, b = b)
print(y)
```
### Function of multiple iterables:
```
f = lambda x, y: x * y
iterable1 = [1, 2, 3]
iterable2 = [4, 5, 6]
# Serial
z = [f(x, y) for x, y in zip(iterable1, iterable2)]
print(z)
# Parallel
z = parabar.map(f, zip(iterable1, iterable2))
print(z)
```
### Function of multiple iterables, with non-iterable args and kwargs
```
f = lambda x, y, a, b = 0: x * y * a + b
iterable1 = [1, 2, 3]
iterable2 = [4, 5, 6]
a = 1
b = 0
# Serial
z = [f(x, y, a, b = b) for x, y in zip(iterable1, iterable2)]
print(z)
# Parallel
z = parabar.map(f, zip(iterable1, iterable2), a, b = b)
print(z)
```
### Specify number of processes and keyword arguments for progress bar
```
from tqdm.auto import tqdm
f = lambda x: x
iterable = [1, 2, 3]
tqdm_kwargs = dict(total = 3, desc = 'iterating')
# Serial
y = [f(x) for x in tqdm(iterable, **tqdm_kwargs)]
print(y)
# Parallel
y = parabar.map(f, iterable, ncpus=2, tqdm_kwargs=tqdm_kwargs)
print(y)
```
Raw data
{
"_id": null,
"home_page": "https://github.com/mdmould/parabar",
"name": "parabar",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "",
"author": "Matthew Mould",
"author_email": "mattdmould@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/99/32/334f1dcc53a2ee911671a90b306421f5084d2b82194e436999ffbabe8607/parabar-0.2.tar.gz",
"platform": null,
"description": "# parabar\n\nProgress bars from `tqdm` for multiprocessing with `pathos` in Python.\n\nThis is similar in spirit to `tqdm_pathos` but more simplified.\n\n## Installation\n\n`pip install parabar`\n\n## Usage\n\nThere is a single function `parabar.map`.\n\nThe two required arguments are the function you want to map and the iterable(s) you want to map over: `parabar.map(func, iterable)`.\n\nIf you want to iterate over multiple arguments, you should zip them: `parabar.map(func, zip(iterable1, iterable2))`.\n\nIt has two optional arguments:\n- `ncpus = 1`: the number of processes for the pool\n- `tqdm_kwargs = {}`: dictionary of extra arguments to pass to `tqdm`.\n\nIf the length of your iterable is `total`, you can tell `tqdm` by using `tqdm_kargs = {'total': total}`. Otherwise, `parabar.map` will convert your iterables to a list and use `len`.\n\nYou can provide other fixed positional and keywords arguments to your function that you do not want to iterate over as the reminaing position and keyword arguments: `parabar.map(func, iterable, arg1, arg2, kwarg1=None, ncpus=1)`.\n\n## Examples\n\n### Function of a single iterable:\n\n```\nf = lambda x: x**2\niterable = [1, 2, 3]\n\n# Serial\ny = [f(x) for x in iterable]\nprint(y)\n\n# Parallel\ny = parabar.map(f, iterable)\nprint(y)\n```\n\n### Function of a single iterable, with non-iterable args and kwargs:\n\n```\nf = lambda x, a, b = 0: x**2 * a + b\niterable = [1, 2, 3]\na = 1\nb = 0\n\n# Serial\ny = [f(x, a, b = b) for x in iterable]\nprint(y)\n\n# Parallel\ny = parabar.map(f, iterable, a, b = b)\nprint(y)\n```\n\n### Function of multiple iterables:\n\n```\nf = lambda x, y: x * y\niterable1 = [1, 2, 3]\niterable2 = [4, 5, 6]\n\n# Serial\nz = [f(x, y) for x, y in zip(iterable1, iterable2)]\nprint(z)\n\n# Parallel\nz = parabar.map(f, zip(iterable1, iterable2))\nprint(z)\n```\n\n### Function of multiple iterables, with non-iterable args and kwargs\n\n```\nf = lambda x, y, a, b = 0: x * y * a + b\niterable1 = [1, 2, 3]\niterable2 = [4, 5, 6]\na = 1\nb = 0\n\n# Serial\nz = [f(x, y, a, b = b) for x, y in zip(iterable1, iterable2)]\nprint(z)\n\n# Parallel\nz = parabar.map(f, zip(iterable1, iterable2), a, b = b)\nprint(z)\n```\n\n### Specify number of processes and keyword arguments for progress bar\n\n```\nfrom tqdm.auto import tqdm\n\nf = lambda x: x\niterable = [1, 2, 3]\ntqdm_kwargs = dict(total = 3, desc = 'iterating')\n\n# Serial\ny = [f(x) for x in tqdm(iterable, **tqdm_kwargs)]\nprint(y)\n\n# Parallel\ny = parabar.map(f, iterable, ncpus=2, tqdm_kwargs=tqdm_kwargs)\nprint(y)\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "parabar",
"version": "0.2",
"project_urls": {
"Homepage": "https://github.com/mdmould/parabar"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6702f434c3f684e93348f6098c06e5d4e70180867ce67ad640237f83f52157fe",
"md5": "87c80ee63afd2b6216e9da70d76189b3",
"sha256": "0b8cc55a98c6a5c2aa37513558b63d2abbb5957677c6d8f3f3c94636c41b4759"
},
"downloads": -1,
"filename": "parabar-0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "87c80ee63afd2b6216e9da70d76189b3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 3325,
"upload_time": "2023-11-11T22:18:10",
"upload_time_iso_8601": "2023-11-11T22:18:10.043318Z",
"url": "https://files.pythonhosted.org/packages/67/02/f434c3f684e93348f6098c06e5d4e70180867ce67ad640237f83f52157fe/parabar-0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9932334f1dcc53a2ee911671a90b306421f5084d2b82194e436999ffbabe8607",
"md5": "bd32fec2defbc337b65c7b797f981d61",
"sha256": "bf9f148e00cea587caad51eb0ce607550f07a9710d41eea957c12f78c1ada572"
},
"downloads": -1,
"filename": "parabar-0.2.tar.gz",
"has_sig": false,
"md5_digest": "bd32fec2defbc337b65c7b797f981d61",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 3071,
"upload_time": "2023-11-11T22:18:11",
"upload_time_iso_8601": "2023-11-11T22:18:11.353993Z",
"url": "https://files.pythonhosted.org/packages/99/32/334f1dcc53a2ee911671a90b306421f5084d2b82194e436999ffbabe8607/parabar-0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-11 22:18:11",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mdmould",
"github_project": "parabar",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "parabar"
}