# print-on-steroids :weight_lifting_man:
 [](https://anaconda.org/conda-forge/print-on-steroids) [](https://pypi.python.org/pypi/print-on-steroids)   
A lean and hackable rich logger and drop-in enhanced replacement for the native `print` function.
## Installation
You can install `print-on-steroids` with `pip`:
```bash
pip install print-on-steroids
```
or `conda`:
```bash
conda install -c conda-forge print-on-steroids
```
We use the `better-exceptions` package if available to pretty print tracebacks. To install `better-exceptions`, use `pip install print-on-steroids[exceptions]` instead or run `pip install better-exceptions` manually.
## Features
- Support for logging only on rank zero in distributed setups (e.g. DistributedDataParallel or sharded training in Deep Learning)
- Gracefully handles `tqdm` and `tqdm.rich` progress bars (logs during training do not interrupt the progress bar!)
- A context manager and decorator for beautiful and enriched exception printing
- Rich meta-information for free like timestamps and originating line of code (turned into a clickable deeplink by VS Code)
- Easy switching between `dev` and `package` modes when publishing packages to PyPI (cleaner logs without clutter)
## Usage
`print_on_steroids` - like `print` but on steroids!
```python
from print_on_steroids import print_on_steroids as print
# Enjoy enhanced print with optional log levels, timestamp, and originating line of code
print("Enhanced", "print!", level="success", print_time=True, print_origin=True)
# Logging with multiple processes - avoid terminal clutter
print("Gets printed", rank=0, rank0_only=True)
print("Doesn't get printed", rank=1, rank0_only=True)
```
Use `logger` for more advanced use cases:
```python
from print_on_steroids import logger
# Full-fledged logger object out-of-the-box
logger.log("This", "is", "cool", level="info")
# or give the log level directly:
logger.info("This", "is", "cool")
logger.warning("This", "is", "dangerous")
logger.error("This", "is", "fatal")
...
# Easy setup for distributed setting:
logger.config(rank=RANK, print_rank0_only=True)
# Afterwards, the rank is remembered and does not need to be passed agai
logger.success("Dataset processing finished!") # <-- this now prints only on rank zero
# For cleaner logs when publishing a package, use this:
logger.config(mode="package", package_name="MyPackage")
```
All methods gracefully handle `tqdm` - no interrupted progress bars:
```python
from print_on_steroids import logger, print_on_steroids as print
from tqdm import tqdm
for i in tqdm(range(42), desc="This works!"):
sleep(1)
logger.success("Work done:", i)
print_on_steroids("Work done:", i)
```
Beautifully formatted Exception and traceback printing:
```python
from print_on_steroids import graceful_exceptions
# As a context manager:
with graceful_exceptions():
# Do stuff...
# As a decorator:
@graceful_exceptions()
def do_stuff():
# Do stuff...
```
Raw data
{
"_id": null,
"home_page": "https://github.com/konstantinjdobler/print-on-steroids",
"name": "print-on-steroids",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "",
"author": "",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/f7/13/72952e34831493d98104a2e726277502ab65503c307a1ef570a9f29b2965/print-on-steroids-1.2.3.tar.gz",
"platform": null,
"description": "# print-on-steroids :weight_lifting_man:\n\n [](https://anaconda.org/conda-forge/print-on-steroids) [](https://pypi.python.org/pypi/print-on-steroids)   \n\nA lean and hackable rich logger and drop-in enhanced replacement for the native `print` function.\n\n## Installation\n\nYou can install `print-on-steroids` with `pip`:\n\n```bash\npip install print-on-steroids\n```\n\nor `conda`:\n\n```bash\nconda install -c conda-forge print-on-steroids\n```\n\nWe use the `better-exceptions` package if available to pretty print tracebacks. To install `better-exceptions`, use `pip install print-on-steroids[exceptions]` instead or run `pip install better-exceptions` manually.\n\n## Features\n\n- Support for logging only on rank zero in distributed setups (e.g. DistributedDataParallel or sharded training in Deep Learning)\n- Gracefully handles `tqdm` and `tqdm.rich` progress bars (logs during training do not interrupt the progress bar!)\n- A context manager and decorator for beautiful and enriched exception printing\n- Rich meta-information for free like timestamps and originating line of code (turned into a clickable deeplink by VS Code)\n- Easy switching between `dev` and `package` modes when publishing packages to PyPI (cleaner logs without clutter)\n\n## Usage\n\n`print_on_steroids` - like `print` but on steroids!\n\n```python\nfrom print_on_steroids import print_on_steroids as print\n\n# Enjoy enhanced print with optional log levels, timestamp, and originating line of code\nprint(\"Enhanced\", \"print!\", level=\"success\", print_time=True, print_origin=True)\n\n# Logging with multiple processes - avoid terminal clutter\nprint(\"Gets printed\", rank=0, rank0_only=True)\nprint(\"Doesn't get printed\", rank=1, rank0_only=True)\n```\n\nUse `logger` for more advanced use cases:\n\n```python\nfrom print_on_steroids import logger\n\n# Full-fledged logger object out-of-the-box\nlogger.log(\"This\", \"is\", \"cool\", level=\"info\")\n# or give the log level directly:\nlogger.info(\"This\", \"is\", \"cool\")\nlogger.warning(\"This\", \"is\", \"dangerous\")\nlogger.error(\"This\", \"is\", \"fatal\")\n...\n\n# Easy setup for distributed setting:\nlogger.config(rank=RANK, print_rank0_only=True)\n# Afterwards, the rank is remembered and does not need to be passed agai\nlogger.success(\"Dataset processing finished!\") # <-- this now prints only on rank zero\n\n# For cleaner logs when publishing a package, use this:\nlogger.config(mode=\"package\", package_name=\"MyPackage\")\n```\n\nAll methods gracefully handle `tqdm` - no interrupted progress bars:\n\n```python\nfrom print_on_steroids import logger, print_on_steroids as print\nfrom tqdm import tqdm\n\nfor i in tqdm(range(42), desc=\"This works!\"):\n sleep(1)\n logger.success(\"Work done:\", i)\n print_on_steroids(\"Work done:\", i)\n```\n\nBeautifully formatted Exception and traceback printing:\n\n```python\nfrom print_on_steroids import graceful_exceptions\n\n# As a context manager:\nwith graceful_exceptions():\n # Do stuff...\n\n# As a decorator:\n@graceful_exceptions()\ndef do_stuff():\n # Do stuff...\n```\n",
"bugtrack_url": null,
"license": "",
"summary": "A lean & hackable rich logger and print function.",
"version": "1.2.3",
"project_urls": {
"Bug Tracker": "https://github.com/konstantinjdobler/print-on-steroids/issues",
"Changelog": "https://github.com/konstantinjdobler/print-on-steroids/releases",
"Homepage": "https://github.com/konstantinjdobler/print-on-steroids"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6189e81e3b458b777a4fefb265e3d7501775675a2465a57ae50b9f9a240ec092",
"md5": "635a283fa05dd731f862f6053c8d4fa6",
"sha256": "ed8e28a3b798d86cc9c185486ba713948600db433c2e3f562606b6d1322dc951"
},
"downloads": -1,
"filename": "print_on_steroids-1.2.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "635a283fa05dd731f862f6053c8d4fa6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 8741,
"upload_time": "2023-09-11T17:07:52",
"upload_time_iso_8601": "2023-09-11T17:07:52.149971Z",
"url": "https://files.pythonhosted.org/packages/61/89/e81e3b458b777a4fefb265e3d7501775675a2465a57ae50b9f9a240ec092/print_on_steroids-1.2.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f71372952e34831493d98104a2e726277502ab65503c307a1ef570a9f29b2965",
"md5": "2829d59fb092881e453d7f21093f091c",
"sha256": "3d2027511c6cd68e3ed808b34270bfc2141bdfbf697dccc14248a60e0037aef5"
},
"downloads": -1,
"filename": "print-on-steroids-1.2.3.tar.gz",
"has_sig": false,
"md5_digest": "2829d59fb092881e453d7f21093f091c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 12893,
"upload_time": "2023-09-11T17:07:53",
"upload_time_iso_8601": "2023-09-11T17:07:53.717895Z",
"url": "https://files.pythonhosted.org/packages/f7/13/72952e34831493d98104a2e726277502ab65503c307a1ef570a9f29b2965/print-on-steroids-1.2.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-11 17:07:53",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "konstantinjdobler",
"github_project": "print-on-steroids",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "rich",
"specs": []
},
{
"name": "tqdm",
"specs": []
},
{
"name": "better-exceptions",
"specs": []
}
],
"lcname": "print-on-steroids"
}