freshcrate

wasabi

A lightweight console printing and formatting toolkit

Description

# wasabi: A lightweight console printing and formatting toolkit Over the years, I've written countless implementations of coloring and formatting utilities to output messages in our libraries like [spaCy](https://spacy.io), [Thinc](https://github.com/explosion/thinc) and [Prodigy](https://prodi.gy). While there are many other great open-source options, I've always ended up wanting something slightly different or slightly custom. This package is still a work in progress and aims to bundle those utilities in a standardised way so they can be shared across our other projects. It's super lightweight, has zero dependencies and works with Python 3.6+. [![tests](https://github.com/explosion/wasabi/actions/workflows/tests.yml/badge.svg)](https://github.com/explosion/wasabi/actions/workflows/tests.yml) [![PyPi](https://img.shields.io/pypi/v/wasabi.svg?style=flat-square&logo=pypi&logoColor=white)](https://pypi.python.org/pypi/wasabi) [![conda](https://img.shields.io/conda/vn/conda-forge/wasabi.svg?style=flat-square&logo=conda-forge/logoColor=white)](https://anaconda.org/conda-forge/wasabi) [![GitHub](https://img.shields.io/github/release/ines/wasabi/all.svg?style=flat-square&logo=github)](https://github.com/ines/wasabi) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square)](https://github.com/ambv/black) <img width="609" src="https://user-images.githubusercontent.com/13643239/48663861-8c9ea000-ea96-11e8-8b04-d120c52276a8.png"> ## πŸ’¬ FAQ ### Are you going to add more features? Yes, there's still a few of helpers and features to port over. However, the new features will be heavily biased by what we (think we) need. I always appreciate pull requests to improve the existing functionality – but I want to keep this library as simple, lightweight and specific as possible. ### Can I use this for my projects? Sure, if you like it, feel free to adopt it! Just keep in mind that the package is very specific and not intended to be a full-featured and fully customisable formatting library. If that's what you're looking for, you might want to try other packages – for example, [`colored`](https://pypi.org/project/colored/), [`crayons`](https://github.com/kennethreitz/crayons), [`colorful`](https://github.com/timofurrer/colorful), [`tabulate`](https://bitbucket.org/astanin/python-tabulate), [`console`](https://github.com/mixmastamyk/console) or [`py-term`](https://github.com/gravmatt/py-term), to name a few. ### Why `wasabi`? I was looking for a short and descriptive name, but everything was already taken. So I ended up naming this package after one of my rats, Wasabi. πŸ€ ## βŒ›οΈ Installation ```bash pip install wasabi ``` ## πŸŽ› API ### <kbd>function</kbd> `msg` An instance of `Printer`, initialized with the default config. Useful as a quick shortcut if you don't need to customize initialization. ```python from wasabi import msg msg.good("Success!") ``` ### <kbd>class</kbd> `Printer` #### <kbd>method</kbd> `Printer.__init__` ```python from wasabi import Printer msg = Printer() ``` | Argument | Type | Description | Default | | ----------------- | --------- | ------------------------------------------------------------- | ------------- | | `pretty` | bool | Pretty-print output with colors and icons. | `True` | | `no_print` | bool | Don't actually print, just return. | `False` | | `colors` | dict | Add or overwrite color values, names mapped to `0`-`256`. | `None` | | `icons` | dict | Add or overwrite icon. Name mapped to unicode. | `None` | | `line_max` | int | Maximum line length (for divider). | `80` | | `animation` | str | Steps of loading animation for `Printer.loading`. | `"⠙⠹⠸⠼⠴⠦⠧⠇⠏"` | | `animation_ascii` | str | Alternative animation for ASCII terminals. | `"\|/-\\"` | | `hide_animation` | bool | Don't display animation, e.g. for logs. | `False` | | `ignore_warnings` | bool | Don't output messages of type `MESSAGE.WARN`. | `False` | | `env_prefix` | str | Prefix for environment variables, e.g. `WASABI_LOG_FRIENDLY`. | `"WASABI"` | | `timestamp` | bool | Add timestamp before output. | `False` | | **RETURNS** | `Printer` | The initialized printer. | - | #### <kbd>method</kbd> `Printer.text` ```python msg = Printer() msg.text("Hello world!") ``` | Argument | Type | Description | Default | | ---------- | -------------- | -------------------------------------

Release History

VersionChangesUrgencyDate
1.1.3Imported from PyPI (1.1.3)Low4/21/2026
v1.1.3## ✨ Fixes and features * Add support for Python 3.12 on the CI (#44) * Further updates to the CI (#45) * Allow `typing-extensions<5.0.0` for Python < 3.8 (#46) ## πŸ‘₯ Contributors @adrianeboyd, @honnibal, @ines, @svlandeg Low5/31/2024
v1.1.2* Add typing overloads so `msg.fail` with `exits=True/1` has the `NoReturn` type like `sys.exit` (#41).Low6/7/2023
v1.1.1* Fix `typing_extensions` requirement and usage across Python versions (#32).Low1/16/2023
v1.1.0* Drop support for Python 3.5 and earlier (#22). * Add type hints, support mypy 0.990+ (#22). * Add support for ANSI on Windows (#31).Low12/7/2022
v0.10.1* Revert Windows ANSI support detection changes for now.Low7/28/2022
v0.10.0* Add support for Windows consoles with full ANSI support Thanks @njsmith for the pull request!Low7/27/2022
v0.9.1* Add symbols to `diff_strings`.Low3/30/2022
v0.9.0- Allow foreground and background colors to be specified for individual table columns. - Allow color values as well as color names as the `color` parameter to `Printer.text()`. - Add a new `bg_color`parameter to `Printer.text()`. - Correct a couple of minor documentation errors. - Add version to `__init__.py`.Low12/6/2021
v0.8.2* Add `aligns` support for table headers.Low1/31/2021
v0.8.1* Correctly respect `show` on `Printer.divider`. * Fix automated build.Low1/25/2021
v0.8.0* Add `MarkdownRenderer` for creating Markdown-formatted documents. * Update `diff_strings` so it diffs lines and produces more usable results.Low8/26/2020
v0.7.1* Fix `diff_strings` for replacements.Low7/16/2020
v0.7.0* Raise Python exception for messages with non-zero exit code if `no_print` is enabled.Low6/21/2020
v0.6.0* Add `timestamp` flag to `Printer` to show timestamp with message. Thanks to @svlandeg for the pull request!Low1/3/2020
v0.5.0* Make traceback links clickable in `TracebackPrinter`. * Allow configuring the traceback frame range in `TracebackPrinter`. * Convert file paths in `TracebackPrinter` to relative if given `tb_base="."`. Thanks to @justindujardin for the pull requests!Low12/28/2019
v0.4.2* Support `icon` in divider (added before the text).Low12/2/2019
v0.4.1* Add `spaced` argument to printers to wrap output in newlines.Low12/2/2019
v0.4.0* Add `wasabi.msg` shortcut, an instance of `Printer` with the default configuration.Low11/3/2019
v0.3.0* Add `diff_strings` utility. * Support multline values im tables via `multiline` option. * Fix rendering of dividers if `pretty` is disabled.Low10/24/2019
v0.2.2* Fix handling of `no_print=True` in loading context manager. (#2)Low5/4/2019
v0.2.1* Handle cases where `sys.stdout` doesn't have `encoding` attribute.Low3/26/2019
v0.2.0* Improve handling of non-UTF-8 terminals and add fallback icons. * Improve test suite and CI to catch unicode issues.Low3/22/2019
v0.1.3* Supports single widths argument on row. * Replace Travis and Appveyor with Azure Pipelines.Low3/16/2019
v0.1.2* Move tests to `wasabi.tests` to bundle them with package. * Set `zip_safe=True`.Low2/24/2019
v0.1.1* Add `MANIFEST.in`.Low2/24/2019
v0.1.0* Fix handling of `no_print`.Low2/24/2019
v0.0.15* Add default encoding in `util.can_render` in case `sys.stdout.encoding` is `None`.Low12/19/2018
v0.0.14* Fix list values passed as `aligns` and make align check more elegant.Low12/10/2018
v0.0.13* Change default `LOG_FRIENDLY` environment variable to `WASABI_LOG_FRIENDLY`. * Support custom environment variables via `env_prefix` argument.Low12/10/2018
v0.0.12* Support single align value in table as `aligns` argument, e.g. `aligns="r"`. * Tidy up loading without animation.Low12/8/2018
v0.0.11* Expose `table` and `row` in top-level module. * Add `hide_animation` argument to `Printer`. * Support `LOG_FRIENDLY` environment variable to disable animations and color. * Update API docs.Low12/8/2018
v0.0.10* Fix display of traceback printer with only title.Low12/2/2018
v0.0.9* Add `format_repr` method as a wrapper aroud `repr()`. * Add `TracebackPrinter` for custom formatted tracebacks.Low12/2/2018
v0.0.8* Add `Printer.row` method for single table rows.Low11/30/2018
v0.0.7* Fix exception handling within `Printer.loading` context manager.Low11/30/2018
v0.0.6* Remove unused code. * Add Appveyor testing for Windows. * Improve support on non-ANSI terminals. * Fix encoding issue in `setup.py`.Low11/27/2018
v0.0.5* Add `exits` argument to perform system exit. * Allow `title` amd optional `text` argument on main text printers. * Make sure wrapping doesn't strip out added newlines.Low11/18/2018
v0.0.4* Fix setup on Python 2.7. * Add `table` and `Printer.table` utilities.Low11/18/2018
v0.0.3* Add `Printer.loading` contextmanager for loading animations. * Tidy up and auto-format with [Black](https://github.com/ambv/black).Low11/17/2018
v0.0.2Release v0.0.2Low11/17/2018

Dependencies & License Audit

Loading dependencies...

Similar Packages

azure-coreMicrosoft Azure Core Library for Pythonazure-template_0.1.0b6187637
azure-mgmt-coreMicrosoft Azure Management Core Library for Pythonazure-template_0.1.0b6187637
azure-monitor-opentelemetry-exporterMicrosoft Azure Monitor Opentelemetry Exporter Client Library for Pythonazure-template_0.1.0b6187637
azure-servicebusMicrosoft Azure Service Bus Client Library for Pythonazure-template_0.1.0b6187637
azure-monitor-opentelemetryMicrosoft Azure Monitor Opentelemetry Distro Client Library for Pythonazure-template_0.1.0b6187637