Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docs/llms_intro.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
ansitable prints tabular data and NumPy matrices in a terminal with optional Unicode borders and ANSI color, and exports the same table to Markdown, HTML, LaTeX, reStructuredText, wikitable, CSV and Pandas. It is a small, pure-Python package (one module, `ansitable.table`) whose only dependency is the `colored` package, which provides the color names. It requires Python 3.9 or later. Install with `pip install ansitable`.

## When to use it

Reach for ansitable when a program needs to show **rows of values or a NumPy matrix as a neat table in a terminal**, optionally with color and box-drawing borders, and especially when the *same* table must also go into a document (Markdown, LaTeX, HTML, reStructuredText, wikitable, CSV) or a Pandas DataFrame. It is small and has one dependency, `colored`, which is optional for output without color.

It is not a general terminal UI toolkit (use `rich` or `textual` for live layouts, progress bars, panels), and it is not a data-wrangling library (use Pandas). It is a good fit when you want a plain, dependable table with a few lines of code.

## Quick start

```python
Expand All @@ -17,6 +23,15 @@ table.sort("Score", key=float, reverse=True) # in place; returns the tabl
table.print() # to a terminal, or table.print(file=f)
```

## Recipes

- **Print a table of results**: `t = ANSITable("name", "value", border="thin")`, then `t.row("a", 1.5)` for each row, then `t.print()`.
- **Show a NumPy matrix neatly**: `ANSIMatrix().print(A)`, or `str_ = ANSIMatrix(fmt="{:8.3f}").str(A)` for a string.
- **Show a Pandas DataFrame as a table**: `ANSITable.Pandas(df).print()`.
- **Put the same table in a Markdown or LaTeX document**: `t.markdown()`, `t.latex()`, or `t.export(file="results.md")`, which picks the format from the file extension.
- **Turn color and Unicode off for log files**: `ansitable.options(use_unicode=False, color=False)`.
- **Color one row or cell**: `t.row(..., fgcolor="red")`, or wrap a value in `Cell("text", fgcolor="red")`.

## Key points

- **Creating a table.** `ANSITable("a", "b", "c")` makes columns from strings (right-aligned, formatted with `"{}"`). Pass `Column(name, fmt=..., width=..., colcolor=..., colalign=..., headstyle=...)` objects instead for formatting and styling, or call `table.addcolumn(name, **kwargs)`. An alignment marker at the start of a column name, such as `"{<}Name"`, `"{^}Name"`, sets alignment in the string form.
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ dependencies = ["colored"]
"Homepage" = "https://github.com/petercorke/ansitable"
"Bug Tracker" = "https://github.com/petercorke/ansitable/issues"
"Documentation" = "https://petercorke.github.io/ansitable"
"llms.txt" = "https://petercorke.github.io/ansitable/llms.txt"
"Source" = "https://github.com/petercorke/ansitable"

[project.optional-dependencies]
Expand Down
Loading