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+. [](https://github.com/explosion/wasabi/actions/workflows/tests.yml) [](https://pypi.python.org/pypi/wasabi) [](https://anaconda.org/conda-forge/wasabi) [](https://github.com/ines/wasabi) [](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
| Version | Changes | Urgency | Date |
|---|---|---|---|
| 1.1.3 | Imported from PyPI (1.1.3) | Low | 4/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 | Low | 5/31/2024 |
| v1.1.2 | * Add typing overloads so `msg.fail` with `exits=True/1` has the `NoReturn` type like `sys.exit` (#41). | Low | 6/7/2023 |
| v1.1.1 | * Fix `typing_extensions` requirement and usage across Python versions (#32). | Low | 1/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). | Low | 12/7/2022 |
| v0.10.1 | * Revert Windows ANSI support detection changes for now. | Low | 7/28/2022 |
| v0.10.0 | * Add support for Windows consoles with full ANSI support Thanks @njsmith for the pull request! | Low | 7/27/2022 |
| v0.9.1 | * Add symbols to `diff_strings`. | Low | 3/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`. | Low | 12/6/2021 |
| v0.8.2 | * Add `aligns` support for table headers. | Low | 1/31/2021 |
| v0.8.1 | * Correctly respect `show` on `Printer.divider`. * Fix automated build. | Low | 1/25/2021 |
| v0.8.0 | * Add `MarkdownRenderer` for creating Markdown-formatted documents. * Update `diff_strings` so it diffs lines and produces more usable results. | Low | 8/26/2020 |
| v0.7.1 | * Fix `diff_strings` for replacements. | Low | 7/16/2020 |
| v0.7.0 | * Raise Python exception for messages with non-zero exit code if `no_print` is enabled. | Low | 6/21/2020 |
| v0.6.0 | * Add `timestamp` flag to `Printer` to show timestamp with message. Thanks to @svlandeg for the pull request! | Low | 1/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! | Low | 12/28/2019 |
| v0.4.2 | * Support `icon` in divider (added before the text). | Low | 12/2/2019 |
| v0.4.1 | * Add `spaced` argument to printers to wrap output in newlines. | Low | 12/2/2019 |
| v0.4.0 | * Add `wasabi.msg` shortcut, an instance of `Printer` with the default configuration. | Low | 11/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. | Low | 10/24/2019 |
| v0.2.2 | * Fix handling of `no_print=True` in loading context manager. (#2) | Low | 5/4/2019 |
| v0.2.1 | * Handle cases where `sys.stdout` doesn't have `encoding` attribute. | Low | 3/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. | Low | 3/22/2019 |
| v0.1.3 | * Supports single widths argument on row. * Replace Travis and Appveyor with Azure Pipelines. | Low | 3/16/2019 |
| v0.1.2 | * Move tests to `wasabi.tests` to bundle them with package. * Set `zip_safe=True`. | Low | 2/24/2019 |
| v0.1.1 | * Add `MANIFEST.in`. | Low | 2/24/2019 |
| v0.1.0 | * Fix handling of `no_print`. | Low | 2/24/2019 |
| v0.0.15 | * Add default encoding in `util.can_render` in case `sys.stdout.encoding` is `None`. | Low | 12/19/2018 |
| v0.0.14 | * Fix list values passed as `aligns` and make align check more elegant. | Low | 12/10/2018 |
| v0.0.13 | * Change default `LOG_FRIENDLY` environment variable to `WASABI_LOG_FRIENDLY`. * Support custom environment variables via `env_prefix` argument. | Low | 12/10/2018 |
| v0.0.12 | * Support single align value in table as `aligns` argument, e.g. `aligns="r"`. * Tidy up loading without animation. | Low | 12/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. | Low | 12/8/2018 |
| v0.0.10 | * Fix display of traceback printer with only title. | Low | 12/2/2018 |
| v0.0.9 | * Add `format_repr` method as a wrapper aroud `repr()`. * Add `TracebackPrinter` for custom formatted tracebacks. | Low | 12/2/2018 |
| v0.0.8 | * Add `Printer.row` method for single table rows. | Low | 11/30/2018 |
| v0.0.7 | * Fix exception handling within `Printer.loading` context manager. | Low | 11/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`. | Low | 11/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. | Low | 11/18/2018 |
| v0.0.4 | * Fix setup on Python 2.7. * Add `table` and `Printer.table` utilities. | Low | 11/18/2018 |
| v0.0.3 | * Add `Printer.loading` contextmanager for loading animations. * Tidy up and auto-format with [Black](https://github.com/ambv/black). | Low | 11/17/2018 |
| v0.0.2 | Release v0.0.2 | Low | 11/17/2018 |
