cleantimer


Namecleantimer JSON
Version 0.0.2 PyPI version JSON
download
home_pagehttps://github.com/alecglen/cleantimer
SummaryTrack progress of long-running scripts, without cluttering your code with log statements.
upload_time2023-10-29 03:07:34
maintainer
docs_urlNone
authorAlec Ostrander
requires_python>=3.6
licenseGPLv3
keywords time timer progress
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # cleantimer

Track progress of long-running scripts, without cluttering your code with log statements.

cleantimer is a minimal wrapper around a couple of my favorite packages for timing scripts - [contexttimer](https://pypi.org/project/contexttimer/) and [tqdm](https://pypi.org/project/tqdm/). It merges their most useful features in a clean API based simply on the way I've found I like to use them. Hopefully you find it simply useful. 😊

## Installation

`pip install cleantimer`

### Import:

`from cleantimer import CTimer`

## Use cases

### A basic timer with a message for what you're timing:

```Python
with CTimer("Waking up"):
    sleep(4)
```

```
Waking up (3:22PM)...done. (4.0s)
```

### Print with varying precision:

```Python
with CTimer("Waking up", 3):
    sleep(4.123456)
```

```
Waking up (3:22PM)...done. (4.123s)
```

### Sub-timers

```Python
with CTimer("Making breakfast") as timer:
    sleep(2)
    with timer.child("cooking eggs") as eggtimer:
        sleep(3)
    with timer.child("pouring juice"):
        sleep(1)
```

```
Making breakfast (3:22PM)...
    cooking eggs (3:22PM)...done. (3.0s)
    pouring juice (3:23PM)...done. (1.0s)
done. (6.0s)
```

### Progress meter on a Pandas apply

```Python
df = pd.DataFrame({"A": list(range(10000))})
def times2(row): return row["A"] * 2

with CTimer("Computing doubles") as timer:
    df["2A"] = timer.progress_apply(df, times2)
```

```
Computing doubles (3:22PM)...
    : 100% ██████████████████████████ 10000/10000 [00:07<00:00, 135869it/s]
done. (7.4s)
```

### Segmented progress meter

```Python
df = pd.DataFrame({"A": list(range(10000)), "type": [1]*5000 + [2]*5000})
def times2(row): return row["A"] * 2

with CTimer("Computing doubles") as timer:
    df["2A"] = timer.progress_apply(df, times2, split_col="type", message="part {}")
```

```
Computing doubles (3:22PM)...
    part 1: 100% ██████████████████████████ 5000/5000 [00:07<00:00, 135869it/s]
    part 2: 100% ██████████████████████████ 5000/5000 [00:07<00:00, 122854it/s]
done. (8.2s)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/alecglen/cleantimer",
    "name": "cleantimer",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "time,timer,progress",
    "author": "Alec Ostrander",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/f1/b7/1211ff034d28971b8c7365a5fafe78d83232e653888a192620df55e7fdb8/cleantimer-0.0.2.tar.gz",
    "platform": null,
    "description": "# cleantimer\n\nTrack progress of long-running scripts, without cluttering your code with log statements.\n\ncleantimer is a minimal wrapper around a couple of my favorite packages for timing scripts - [contexttimer](https://pypi.org/project/contexttimer/) and [tqdm](https://pypi.org/project/tqdm/). It merges their most useful features in a clean API based simply on the way I've found I like to use them. Hopefully you find it simply useful. \ud83d\ude0a\n\n## Installation\n\n`pip install cleantimer`\n\n### Import:\n\n`from cleantimer import CTimer`\n\n## Use cases\n\n### A basic timer with a message for what you're timing:\n\n```Python\nwith CTimer(\"Waking up\"):\n    sleep(4)\n```\n\n```\nWaking up (3:22PM)...done. (4.0s)\n```\n\n### Print with varying precision:\n\n```Python\nwith CTimer(\"Waking up\", 3):\n    sleep(4.123456)\n```\n\n```\nWaking up (3:22PM)...done. (4.123s)\n```\n\n### Sub-timers\n\n```Python\nwith CTimer(\"Making breakfast\") as timer:\n    sleep(2)\n    with timer.child(\"cooking eggs\") as eggtimer:\n        sleep(3)\n    with timer.child(\"pouring juice\"):\n        sleep(1)\n```\n\n```\nMaking breakfast (3:22PM)...\n    cooking eggs (3:22PM)...done. (3.0s)\n    pouring juice (3:23PM)...done. (1.0s)\ndone. (6.0s)\n```\n\n### Progress meter on a Pandas apply\n\n```Python\ndf = pd.DataFrame({\"A\": list(range(10000))})\ndef times2(row): return row[\"A\"] * 2\n\nwith CTimer(\"Computing doubles\") as timer:\n    df[\"2A\"] = timer.progress_apply(df, times2)\n```\n\n```\nComputing doubles (3:22PM)...\n    : 100% \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 10000/10000 [00:07<00:00, 135869it/s]\ndone. (7.4s)\n```\n\n### Segmented progress meter\n\n```Python\ndf = pd.DataFrame({\"A\": list(range(10000)), \"type\": [1]*5000 + [2]*5000})\ndef times2(row): return row[\"A\"] * 2\n\nwith CTimer(\"Computing doubles\") as timer:\n    df[\"2A\"] = timer.progress_apply(df, times2, split_col=\"type\", message=\"part {}\")\n```\n\n```\nComputing doubles (3:22PM)...\n    part 1: 100% \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 5000/5000 [00:07<00:00, 135869it/s]\n    part 2: 100% \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588 5000/5000 [00:07<00:00, 122854it/s]\ndone. (8.2s)\n```\n",
    "bugtrack_url": null,
    "license": "GPLv3",
    "summary": "Track progress of long-running scripts, without cluttering your code with log statements.",
    "version": "0.0.2",
    "project_urls": {
        "Homepage": "https://github.com/alecglen/cleantimer"
    },
    "split_keywords": [
        "time",
        "timer",
        "progress"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "27aad3c9d95f48303f951b5210b3042dcb6d6fffd5270867c2e02c0a5f9b68fc",
                "md5": "a2f9d98482817712db61fdf54644976e",
                "sha256": "d692774600faff7b1eac56eb77ed722d288651c05ac1afc4d0b6b6aabdf9848d"
            },
            "downloads": -1,
            "filename": "cleantimer-0.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a2f9d98482817712db61fdf54644976e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 16116,
            "upload_time": "2023-10-29T03:07:32",
            "upload_time_iso_8601": "2023-10-29T03:07:32.846096Z",
            "url": "https://files.pythonhosted.org/packages/27/aa/d3c9d95f48303f951b5210b3042dcb6d6fffd5270867c2e02c0a5f9b68fc/cleantimer-0.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f1b71211ff034d28971b8c7365a5fafe78d83232e653888a192620df55e7fdb8",
                "md5": "0e6f62945138449281c932bec6bce136",
                "sha256": "91e0a8e1708a2ef19eae3085b3dfe9d1831309648f07d783bc9aaedb37072f3a"
            },
            "downloads": -1,
            "filename": "cleantimer-0.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "0e6f62945138449281c932bec6bce136",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 17182,
            "upload_time": "2023-10-29T03:07:34",
            "upload_time_iso_8601": "2023-10-29T03:07:34.357421Z",
            "url": "https://files.pythonhosted.org/packages/f1/b7/1211ff034d28971b8c7365a5fafe78d83232e653888a192620df55e7fdb8/cleantimer-0.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-29 03:07:34",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "alecglen",
    "github_project": "cleantimer",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "cleantimer"
}
        
Elapsed time: 0.13128s