### Install All Dependencies Source: https://github.com/denvercoder1/table2ascii/blob/main/CONTRIBUTING.md Install all development, documentation, and runtime dependencies at once. ```bash pip install -e ".[dev,docs]" ``` -------------------------------- ### Install Runtime Dependencies Source: https://github.com/denvercoder1/table2ascii/blob/main/CONTRIBUTING.md Install the core dependencies needed to run the project. ```bash pip install -e . ``` -------------------------------- ### Install Documentation Dependencies Source: https://github.com/denvercoder1/table2ascii/blob/main/CONTRIBUTING.md Install dependencies required for building and viewing the project documentation. ```bash pip install -e ".[docs]" ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/denvercoder1/table2ascii/blob/main/CONTRIBUTING.md Install development dependencies using pip. This command ensures you have the necessary tools for development. ```bash pip install -e ".[dev]" ``` -------------------------------- ### Thin Thick Rounded Style Example Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Demonstrates the 'thin_thick_rounded' style for table formatting. This style is useful for creating visually distinct tables with rounded corners and varied line weights. ```none ╭─────┬───────────────────────╮ │ # │ G H R S │ ┝━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━┥ │ 1 │ 30 40 35 30 │ ├─────┼───────────────────────┤ │ 2 │ 30 40 35 30 │ ┝━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━┥ │ SUM │ 130 140 135 130 │ ╰─────┴───────────────────────╯ ``` ```none ╭───┬───────────────────╮ │ 1 │ 30 40 35 30 │ ├───┼───────────────────┤ │ 2 │ 30 40 35 30 │ ╰───┴───────────────────╯ ``` -------------------------------- ### Custom Style from Preset with Overrides Source: https://context7.com/denvercoder1/table2ascii/llms.txt Build a custom style by starting with a preset and then overriding specific characters, such as column separators or edges, using the `.set()` method. ```python from table2ascii import PresetStyle borderless_custom = PresetStyle.thin.set(left_and_right_edge="", col_sep=" ") output = table2ascii( header=["Name", "Age"], body=[["Alice", 30], ["Bob", 25]], style=borderless_custom, ) print(output) ``` -------------------------------- ### Serve Documentation Locally Source: https://github.com/denvercoder1/table2ascii/blob/main/CONTRIBUTING.md Build and serve the project documentation locally. The documentation will be accessible at http://127.0.0.1:8888. ```bash task docs ``` -------------------------------- ### Use Preset Styles Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/usage.rst Apply predefined styles for quick formatting. 'ascii_box' creates a table with ASCII box characters, while 'plain' provides a simple, unformatted output. ```python from table2ascii import table2ascii, Alignment, PresetStyle output = table2ascii( header=["First", "Second", "Third", "Fourth"], body=[["10", "30", "40", "35"], ["20", "10", "20", "5"]], column_widths=[10, 10, 10, 10], style=PresetStyle.ascii_box ) print(output) ``` ```python from table2ascii import table2ascii, Alignment, PresetStyle output = table2ascii( header=["First", "Second", "Third", "Fourth"], body=[["10", "30", "40", "35"], ["20", "10", "20", "5"]], style=PresetStyle.plain, cell_padding=0, alignments=Alignment.LEFT, ) print(output) ``` -------------------------------- ### Basic Table Creation Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/usage.rst Use this to create a basic ASCII table from header, body, and footer data. Ensure all rows have the same number of columns as the header. ```python from table2ascii import table2ascii output = table2ascii( header=["#", "G", "H", "R", "S"], body=[["1", "30", "40", "35", "30"], ["2", "30", "40", "35", "30"]], footer=["SUM", "130", "140", "135", "130"], ) print(output) ``` -------------------------------- ### Show ASCII Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Demonstrates the default ASCII table style. This is a basic representation with simple borders. ```none +-----+-----------------------+ | # | G H R S | +-----+-----------------------+ | 1 | 30 40 35 30 | +-----+-----------------------+ | 2 | 30 40 35 30 | +-----+-----------------------+ | SUM | 130 140 135 130 | +-----+-----------------------+ +---+-------------------+ | 1 | 30 40 35 30 | +---+-------------------+ | 2 | 30 40 35 30 | +---+-------------------+ ``` -------------------------------- ### Use a Preset Style (ASCII Box) Source: https://github.com/denvercoder1/table2ascii/blob/main/README.md Apply predefined table styles using `PresetStyle`. The `ascii_box` style creates a table with borders using ASCII characters. Ensure `PresetStyle` is imported. ```python from table2ascii import table2ascii, Alignment, PresetStyle output = table2ascii( header=["First", "Second", "Third", "Fourth"], body=[["10", "30", "40", "35"], ["20", "10", "20", "5"]], column_widths=[10, 10, 10, 10], style=PresetStyle.ascii_box ) print(output) ``` -------------------------------- ### Show ASCII Compact Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Displays the `ascii_compact` style, which reduces spacing for a more condensed look. ```none +-----+-----------------------+ | # | G H R S | +-----+-----------------------+ | 1 | 30 40 35 30 | | 2 | 30 40 35 30 | +-----+-----------------------+ | SUM | 130 140 135 130 | +-----+-----------------------+ +---+-------------------+ | 1 | 30 40 35 30 | | 2 | 30 40 35 30 | +---+-------------------+ ``` -------------------------------- ### Show ASCII Minimalist Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Illustrates the `ascii_minimalist` style, which uses minimal lines and separators. ```none ----------------------------- # | G H R S ============================= 1 | 30 40 35 30 ----------------------------- 2 | 30 40 35 30 ============================= SUM | 130 140 135 130 ----------------------------- ----------------------- 1 | 30 40 35 30 ----------------------- 2 | 30 40 35 30 ----------------------- ``` -------------------------------- ### Show ASCII Borderless Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Illustrates the `ascii_borderless` style, which uses separators but no full borders. ```none # | G H R S ----- ----- ----- ----- ----- 1 | 30 40 35 30 2 | 30 40 35 30 ----- ----- ----- ----- ----- SUM | 130 140 135 130 1 | 30 40 35 30 2 | 30 40 35 30 ``` -------------------------------- ### Use a Preset Style (Plain) Source: https://github.com/denvercoder1/table2ascii/blob/main/README.md The `plain` preset style generates a simple table without borders, suitable for basic text output. Adjust `cell_padding` and `alignments` for further customization. ```python from table2ascii import table2ascii, Alignment, PresetStyle output = table2ascii( header=["First", "Second", "Third", "Fourth"], body=[["10", "30", "40", "35"], ["20", "10", "20", "5"]], style=PresetStyle.plain, cell_padding=0, alignments=Alignment.LEFT, ) print(output) ``` -------------------------------- ### Plain Table Style Source: https://context7.com/denvercoder1/table2ascii/llms.txt Use the `PresetStyle.plain` to render tables without borders, with space-aligned content and zero cell padding. ```python from table2ascii import Alignment print(table2ascii(**data, style=PresetStyle.plain, cell_padding=0, alignments=Alignment.LEFT)) ``` -------------------------------- ### Thin Compact Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Renders a table with thin borders and compact spacing. Ideal for space-constrained displays. ```none ┌─────┬───────────────────────┐ │ # │ G H R S │ ├─────┼───────────────────────┤ │ 1 │ 30 40 35 30 │ │ 2 │ 30 40 35 30 │ ├─────┼───────────────────────┤ │ SUM │ 130 140 135 130 │ └─────┴───────────────────────┘ ┌───┬───────────────────┐ │ 1 │ 30 40 35 30 │ │ 2 │ 30 40 35 30 │ └───┴───────────────────┘ ``` -------------------------------- ### Show ASCII Rounded Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Demonstrates the `ascii_rounded` style, which uses rounded corners for the table. ```none /============================= | # | G H R S | |=====|=======================| | 1 | 30 40 35 30 | |-----|-----------------------| | 2 | 30 40 35 30 | |=====|=======================| | SUM | 130 140 135 130 | \=====|=======================/ /======================= | 1 | 30 40 35 30 | |---|-------------------| | 2 | 30 40 35 30 | \===|===================/ ``` -------------------------------- ### Show Borderless Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Illustrates the `borderless` style, which uses Unicode characters for separators. ```none # ┃ G H R S ━━━━━ ━━━━━ ━━━━━ ━━━━━ ━━━━━ 1 ┃ 30 40 35 30 2 ┃ 30 40 35 30 ━━━━━ ━━━━━ ━━━━━ ━━━━━ ━━━━━ SUM ┃ 130 140 135 130 ``` -------------------------------- ### Show ASCII Simple Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Displays the `ascii_simple` style, which uses a simpler set of lines for borders. ```none ===== ===== ===== ===== ===== # | G H R S ===== ===== ===== ===== ===== 1 | 30 40 35 30 2 | 30 40 35 30 ===== ===== ===== ===== ===== SUM | 130 140 135 130 ===== ===== ===== ===== ===== === ==== ==== ==== ==== 1 | 30 40 35 30 2 | 30 40 35 30 === ==== ==== ==== ==== ``` -------------------------------- ### Apply ASCII box style to table Source: https://context7.com/denvercoder1/table2ascii/llms.txt Use the `style` parameter with `PresetStyle.ascii_box` to render the table with a classic ASCII box border. ```python from table2ascii import table2ascii, PresetStyle data = dict( header=["First", "Second", "Third", "Fourth"], body=[["10", "30", "40", "35"], ["20", "10", "20", "5"]], column_widths=[10, 10, 10, 10], ) # ASCII box style print(table2ascii(**data, style=PresetStyle.ascii_box)) ``` ```text +----------+----------+----------+----------+ | First | Second | Third | Fourth | +----------+----------+----------+----------+ | 10 | 30 | 40 | 35 | +----------+----------+----------+----------+ | 20 | 10 | 20 | 5 | +----------+----------+----------+----------+ ``` -------------------------------- ### Show ASCII Box Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Presents the `ascii_box` style, which uses a full box border for the table. ```none +-----+-----+-----+-----+-----+ | # | G | H | R | S | +-----+-----+-----+-----+-----+ | 1 | 30 | 40 | 35 | 30 | +-----+-----+-----+-----+-----+ | 2 | 30 | 40 | 35 | 30 | +-----+-----+-----+-----+-----+ | SUM | 130 | 140 | 135 | 130 | +-----+-----+-----+-----+-----+ +---+----+----+----+----+ | 1 | 30 | 40 | 35 | 30 | +---+----+----+----+----+ | 2 | 30 | 40 | 35 | 30 | +---+----+----+----+----+ ``` -------------------------------- ### TableStyle Class Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/api.rst Allows for custom table styling. ```APIDOC ## TableStyle ### Description A class used to define custom styles for ASCII tables, including borders, padding, and alignment. ### Methods * `TableStyle(row_sep_char='-', col_sep_char='|', ...)`: Constructor for creating a custom table style. ``` -------------------------------- ### SupportsStr Class Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/api.rst Provides string representation capabilities. ```APIDOC ## SupportsStr ### Description A mixin class that provides a default string representation for objects. ### Methods * `__str__()`: Returns the string representation of the object. ``` -------------------------------- ### Convert 2D list to table with header, body, and footer Source: https://context7.com/denvercoder1/table2ascii/llms.txt Use the `table2ascii` function with header, body, and footer arguments to create a fully formatted table. Ensure at least one of these data arguments is provided. ```python from table2ascii import table2ascii # Full table with header, body, and footer output = table2ascii( header=["#", "G", "H", "R", "S"], body=[ ["1", "30", "40", "35", "30"], ["2", "30", "40", "35", "30"], ], footer=["SUM", "130", "140", "135", "130"], ) print(output) ``` ```text ╔═════════════════════════════╗ ║ # G H R S ║ ╟─────────────────────────────╢ ║ 1 30 40 35 30 ║ ║ 2 30 40 35 30 ║ ╟─────────────────────────────╢ ║ SUM 130 140 135 130 ║ ╚═════════════════════════════╝ ``` -------------------------------- ### Plain Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Renders tables with plain text, using spaces for alignment. This style is the most basic and has no borders or lines. ```none # G H R S 1 30 40 35 30 2 30 40 35 30 SUM 130 140 135 130 1 30 40 35 30 2 30 40 35 30 ``` -------------------------------- ### Thick Compact Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Renders a table with thick borders and compact spacing. Useful for dense data presentation. ```none ┏━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ # ┃ G H R S ┃ ┣━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━┫ ┃ 1 ┃ 30 40 35 30 ┃ ┃ 2 ┃ 30 40 35 30 ┃ ┣━━━━━╋━━━━━━━━━━━━━━━━━━━━━━━┫ ┃ SUM ┃ 130 140 135 130 ┃ ┗━━━━━┻━━━━━━━━━━━━━━━━━━━━━━━┛ ┏━━━┳━━━━━━━━━━━━━━━━━━━┓ ┃ 1 ┃ 30 40 35 30 ┃ ┃ 2 ┃ 30 40 35 30 ┃ ┗━━━┻━━━━━━━━━━━━━━━━━━━┛ ``` -------------------------------- ### Thin Thick Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Renders a table with a combination of thin and thick borders. Creates a distinct visual hierarchy. ```none ┌─────┬───────────────────────┐ │ # │ G H R S │ ┝━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━┥ │ 1 │ 30 40 35 30 │ ├─────┼───────────────────────┤ │ 2 │ 30 40 35 30 │ ┝━━━━━┿━━━━━━━━━━━━━━━━━━━━━━━┥ │ SUM │ 130 140 135 130 │ └─────┴───────────────────────┘ ``` -------------------------------- ### Lint and Fix Codebase Source: https://github.com/denvercoder1/table2ascii/blob/main/CONTRIBUTING.md Run the linting tasks using Black, isort, and pre-commit hooks to format and clean the codebase. This command automatically fixes most linting issues. ```bash task lint ``` -------------------------------- ### Run Tox Tests Source: https://github.com/denvercoder1/table2ascii/blob/main/CONTRIBUTING.md Execute the Tox test script to verify that the project's functionality remains intact. This is crucial for ensuring code quality. ```bash task test ``` -------------------------------- ### Thin Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Renders a table with thin, single-line borders. Suitable for standard table layouts. ```none ┌─────┬───────────────────────┐ │ # │ G H R S │ ├─────┼───────────────────────┤ │ 1 │ 30 40 35 30 │ ├─────┼───────────────────────┤ │ 2 │ 30 40 35 30 │ ├─────┼───────────────────────┤ │ SUM │ 130 140 135 130 │ └─────┴───────────────────────┘ ┌───┬───────────────────┐ │ 1 │ 30 40 35 30 │ ├───┼───────────────────┤ │ 2 │ 30 40 35 30 │ └───┴───────────────────┘ ``` -------------------------------- ### Set Column Widths and Alignments Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/usage.rst Customize the appearance of your table by specifying column widths and alignment for each column. Supports LEFT, CENTER, RIGHT, and DECIMAL alignments. ```python from table2ascii import table2ascii, Alignment output = table2ascii( header=["Product", "Category", "Price", "Rating"], body=[ ["Milk", "Dairy", "$2.99", "6.283"], ["Cheese", "Dairy", "$10.99", "8.2"], ["Apples", "Produce", "$0.99", "10.00"], ], column_widths=[12, 12, 12, 12], alignments=[Alignment.LEFT, Alignment.CENTER, Alignment.RIGHT, Alignment.DECIMAL], ) print(output) ``` -------------------------------- ### PresetStyle Source: https://context7.com/denvercoder1/table2ascii/llms.txt A class providing over 30 built-in table styles that can be applied using the `style` parameter of `table2ascii`. ```APIDOC ## `PresetStyle` — Built-in named table styles ### Description A class of 30+ ready-to-use `TableStyle` instances. Pass any attribute to the `style` parameter of `table2ascii`. Notable styles include `double_thin_compact` (default), `ascii_box`, `markdown`, `plain`, `borderless`, `thin_rounded`, `thick`, and more. ### Usage Import `PresetStyle` and pass one of its attributes to the `style` parameter of the `table2ascii` function. ### Examples ```python from table2ascii import table2ascii, PresetStyle data = dict( header=["First", "Second", "Third", "Fourth"], body=[["10", "30", "40", "35"], ["20", "10", "20", "5"]], column_widths=[10, 10, 10, 10], ) # ASCII box style print(table2ascii(**data, style=PresetStyle.ascii_box)) # Markdown style (for use inside Markdown tables) print(table2ascii(**data, style=PresetStyle.markdown)) ``` ### Response Example (ascii_box) ``` +----------+----------+----------+----------+ | First | Second | Third | Fourth | +----------+----------+----------+----------+ | 10 | 30 | 40 | 35 | +----------+----------+----------+----------+ | 20 | 10 | 20 | 5 | +----------+----------+----------+----------+ ``` ### Response Example (markdown) ``` First | Second | Third | Fourth ----------|----------|----------|---------- 10 | 30 | 40 | 35 20 | 10 | 20 | 5 ``` ``` -------------------------------- ### Thin Compact Rounded Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Renders a table with thin, rounded borders and compact spacing. Offers a softer aesthetic. ```none ╭─────┬───────────────────────╮ │ # │ G H R S │ ├─────┼───────────────────────┤ │ 1 │ 30 40 35 30 │ │ 2 │ 30 40 35 30 │ ├─────┼───────────────────────┤ │ SUM │ 130 140 135 130 │ ╰─────┴───────────────────────╯ ╭───┬───────────────────╮ │ 1 │ 30 40 35 30 │ │ 2 │ 30 40 35 30 │ ╰───┴───────────────────╯ ``` -------------------------------- ### PresetStyle Class Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/api.rst Provides predefined styles for table formatting. ```APIDOC ## PresetStyle ### Description A class that offers a collection of predefined table styles for easy application. ### Members * `PresetStyle.PLAIN` * `PresetStyle.PLAIN_ALT` * `PresetStyle.GITHUB` * `PresetStyle.MARKDOWN` * `PresetStyle.GRID` * `PresetStyle.GRID_ALT` * `PresetStyle.SIMPLE` * `PresetStyle.SIMPLE_ALT` * `PresetStyle.COMPACT` * `PresetStyle.COMPACT_ALT` * `PresetStyle.ALL_BARS` * `PresetStyle.ALL_BARS_ALT` * `PresetStyle.NONE` ``` -------------------------------- ### Define a Custom Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/README.md Create unique table appearances by defining a custom `TableStyle` from a string. The string format specifies characters for borders, separators, and corners. Import `TableStyle` for this functionality. ```python from table2ascii import table2ascii, TableStyle my_style = TableStyle.from_string("*-..*||:+-+:+ *''*") output = table2ascii( header=["First", "Second", "Third"], body=[["10", "30", "40"], ["20", "10", "20"], ["30", "20", "30"]], style=my_style ) print(output) ``` -------------------------------- ### Thin Double Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Renders a table with thin double-line borders. Provides a distinct visual separation. ```none ┌─────┬───────────────────────┐ │ # │ G H R S │ ╞═════╪═══════════════════════╡ │ 1 │ 30 40 35 30 │ ├─────┼───────────────────────┤ │ 2 │ 30 40 35 30 │ ╞═════╪═══════════════════════╡ │ SUM │ 130 140 135 130 │ └─────┴───────────────────────┘ ┌───┬───────────────────┐ │ 1 │ 30 40 35 30 │ ├───┼───────────────────┤ │ 2 │ 30 40 35 30 │ └───┴───────────────────┘ ``` -------------------------------- ### Simple Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst A simple table style using single and double lines for borders. It offers a balance between visual structure and simplicity. ```none ═════ ═════ ═════ ═════ ═════ # ║ G H R S ═════ ═════ ═════ ═════ ═════ 1 ║ 30 40 35 30 2 ║ 30 40 35 30 ═════ ═════ ═════ ═════ ═════ SUM ║ 130 140 135 130 ═════ ═════ ═════ ═════ ═════ ═══ ════ ════ ════ ════ 1 ║ 30 40 35 30 2 ║ 30 40 35 30 ═══ ════ ════ ════ ════ ``` -------------------------------- ### Show ASCII Double Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Features the `ascii_double` style, using double lines for horizontal separators. ```none +-----+-----------------------+ | # | G H R S | +=====+=======================+ | 1 | 30 40 35 30 | +-----+-----------------------+ | 2 | 30 40 35 30 | +=====+=======================+ | SUM | 130 140 135 130 | +-----+-----------------------+ +---+-------------------+ | 1 | 30 40 35 30 | +---+-------------------+ | 2 | 30 40 35 30 | +---+-------------------+ ``` -------------------------------- ### Show ASCII Rounded Box Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Presents the `ascii_rounded_box` style, combining rounded corners with a full box border. ```none /============================= | # | G | H | R | S | |=====|=====|=====|=====|=====| | 1 | 30 | 40 | 35 | 30 | |-----|-----|-----|-----|-----| | 2 | 30 | 40 | 35 | 30 | |=====|=====|=====|=====|=====| | SUM | 130 | 140 | 135 | 130 | \=====|=====|=====|=====|=====/ /======================= | 1 | 30 | 40 | 35 | 30 | |---|----|----|----|----| | 2 | 30 | 40 | 35 | 30 | \===|====|====|====|==== ``` -------------------------------- ### Simple Footer Cell Merge Source: https://context7.com/denvercoder1/table2ascii/llms.txt Demonstrates a simple merge of cells within the footer using `Merge.LEFT` to combine columns for descriptive text. ```python from table2ascii import table2ascii, Merge, PresetStyle output = table2ascii( header=["Name", "Price", "Category", "Stock"], body=[["Milk", "$2.99", "N/A", Merge.LEFT]], footer=["Description", "Milk is a nutritious beverage", Merge.LEFT, Merge.LEFT], style=PresetStyle.double_box, ) print(output) ``` -------------------------------- ### Catching Column Width Too Small Error Source: https://context7.com/denvercoder1/table2ascii/llms.txt Use this to handle cases where a specified column width is insufficient for the content. Ensure column widths are adequate for the data they contain. ```python from table2ascii import table2ascii from table2ascii import ( ColumnWidthTooSmallError, ) try: table2ascii( header=["A", "B"], column_widths=[1, 5], # column 0 min-width is larger than 1 body=[["Hello", "World"]], ) except ColumnWidthTooSmallError as e: print(e) # Column width too small: The column width for index 0 ... ``` -------------------------------- ### Thin Box Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Renders a table with thin, box-style borders. Provides a clear visual separation for cells. ```none ┌─────┬─────┬─────┬─────┬─────┐ │ # │ G │ H │ R │ S │ ├─────┼─────┼─────┼─────┼─────┤ │ 1 │ 30 │ 40 │ 35 │ 30 │ ├─────┼─────┼─────┼─────┼─────┤ │ 2 │ 30 │ 40 │ 35 │ 30 │ ├─────┼─────┼─────┼─────┼─────┤ │ SUM │ 130 │ 140 │ 135 │ 130 │ └─────┴─────┴─────┴─────┴─────┘ ┌───┬────┬────┬────┬────┐ │ 1 │ 30 │ 40 │ 35 │ 30 │ ├───┼────┼────┼────┼────┤ │ 2 │ 30 │ 40 │ 35 │ 30 │ └───┴────┴────┴────┴────┘ ``` -------------------------------- ### Minimalist Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst A minimalist table style using simple lines and spacing. It's designed for readability with minimal visual clutter. ```none ───────────────────────────── # │ G H R S ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1 │ 30 40 35 30 ───────────────────────────── 2 │ 30 40 35 30 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ SUM │ 130 140 135 130 ───────────────────────────── ─────────────────────── 1 │ 30 40 35 30 ─────────────────────── 2 │ 30 40 35 30 ─────────────────────── ``` -------------------------------- ### TableOptionError Exception Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/api.rst Exception for invalid table options. ```APIDOC ## TableOptionError ### Description Raised when an invalid option is provided to the table2ascii function. ``` -------------------------------- ### Check Typing Errors with Pyright Source: https://github.com/denvercoder1/table2ascii/blob/main/CONTRIBUTING.md Use Pyright to check for type hint errors in the codebase, ensuring type safety and correctness. ```bash task pyright ``` -------------------------------- ### Thick Box Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Renders tables with thick box-drawing characters for all borders, creating a prominent and visually distinct table structure. ```none ┏━━━━━┳━━━━━┳━━━━━┳━━━━━┳━━━━━┓ ┃ # ┃ G ┃ H ┃ R ┃ S ┃ ``` -------------------------------- ### Double Thin Compact Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst A compact table style using a mix of double and single thin lines. It reduces spacing while maintaining a clear structure. ```none ╔═════╦═══════════════════════╗ ║ # ║ G H R S ║ ╟─────╫───────────────────────╢ ║ 1 ║ 30 40 35 30 ║ ║ 2 ║ 30 40 35 30 ║ ╟─────╫───────────────────────╢ ║ SUM ║ 130 140 135 130 ║ ╚═════╩═══════════════════════╝ ╔═══╦═══════════════════╗ ║ 1 ║ 30 40 35 30 ║ ║ 2 ║ 30 40 35 30 ║ ╚═══╩═══════════════════╝ ``` -------------------------------- ### Define a Custom Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/usage.rst Create a unique table style by defining a custom string. Refer to the TableStyle documentation for the character mapping. ```python from table2ascii import table2ascii, TableStyle my_style = TableStyle.from_string("*-..*||:+-+:+ *''*") output = table2ascii( header=["First", "Second", "Third"], body=[["10", "30", "40"], ["20", "10", "20"], ["30", "20", "30"]], style=my_style, ) print(output) ``` -------------------------------- ### Markdown Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Renders tables in standard Markdown format. This style is widely compatible with Markdown parsers. ```none | # | G | H | R | S | |-----|-----|-----|-----|-----| | 1 | 30 | 40 | 35 | 30 | | 2 | 30 | 40 | 35 | 30 | |-----|-----|-----|-----|-----| | SUM | 130 | 140 | 135 | 130 | | 1 | 30 | 40 | 35 | 30 | | 2 | 30 | 40 | 35 | 30 | ``` -------------------------------- ### table2ascii() Source: https://context7.com/denvercoder1/table2ascii/llms.txt The main function to convert a 2D list into a formatted ASCII or Unicode table. It accepts optional header, body, and footer rows, and returns the rendered table as a string. All parameters except the data rows are keyword-only. At least one of header, body, or footer must be provided. ```APIDOC ## `table2ascii()` — Convert a 2D list to an ASCII/Unicode table ### Description The main entry point of the library. Accepts optional `header`, `body`, and `footer` sequences and returns the rendered table as a string. All parameters except the data rows are keyword-only. At least one of `header`, `body`, or `footer` must be provided. ### Parameters - **header** (list, optional): A list representing the header row. - **body** (list, optional): A list of lists representing the body rows. - **footer** (list, optional): A list representing the footer row. - **column_widths** (list[int], optional): Specifies the width for each column. - **alignments** (Alignment or list[Alignment], optional): Specifies the text alignment for each column. Can be a single `Alignment` value or a list of `Alignment` values. - **number_alignments** (Alignment or list[Alignment], optional): Specifies the text alignment for numeric values in each column. - **style** (TableStyle, optional): A `TableStyle` object to define the table's appearance. - **padding** (int, optional): The amount of padding around cell content. ### Request Example ```python from table2ascii import table2ascii # Full table with header, body, and footer output = table2ascii( header=["#", "G", "H", "R", "S"], body=[ ["1", "30", "40", "35", "30"], ["2", "30", "40", "35", "30"], ], footer=["SUM", "130", "140", "135", "130"], ) print(output) ``` ### Response #### Success Response (string) - **output** (str): The rendered table as a string. ### Response Example ``` ╔═════════════════════════╗ ║ # G H R S ║ ╟─────────────────────────────╢ ║ 1 30 40 35 30 ║ ║ 2 30 40 35 30 ║ ╟─────────────────────────────╢ ║ SUM 130 140 135 130 ║ ╚═════════════════════════╝ ``` ``` -------------------------------- ### Double Line Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Renders tables with double horizontal and vertical lines. Useful for clear separation of rows and columns. ```none ╔═════╦═══════════════════════╗ ║ # ║ G H R S ║ ╠═════╬═══════════════════════╣ ║ 1 ║ 30 40 35 30 ║ ╠═════╬═══════════════════════╣ ║ 2 ║ 30 40 35 30 ║ ╠═════╬═══════════════════════╣ ║ SUM ║ 130 140 135 130 ║ ╚═════╩═══════════════════════╝ ╔═══╦═══════════════════╗ ║ 1 ║ 30 40 35 30 ║ ╠═══╬═══════════════════╣ ║ 2 ║ 30 40 35 30 ║ ╚═══╩═══════════════════╝ ``` -------------------------------- ### Custom Table Style from String Source: https://context7.com/denvercoder1/table2ascii/llms.txt Define a custom table style by providing a 30-character string to `TableStyle.from_string()`. Individual characters can be overridden using the `.set()` method. ```python from table2ascii import table2ascii, TableStyle # Define a custom style from a 30-character string my_style = TableStyle.from_string("*-..*||:+-+:+ *''*") output = table2ascii( header=["First", "Second", "Third"], body=[["10", "30", "40"], ["20", "10", "20"], ["30", "20", "30"]], style=my_style, ) print(output) ``` -------------------------------- ### Double Compact Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst A compact version of the double line style, suitable for tables where space is limited. It uses double lines but reduces spacing. ```none ╔═════╦═══════════════════════╗ ║ # ║ G H R S ║ ╠═════╬═══════════════════════╣ ║ 1 ║ 30 40 35 30 ║ ║ 2 ║ 30 40 35 30 ║ ╠═════╬═══════════════════════╣ ║ SUM ║ 130 140 135 130 ║ ╚═════╩═══════════════════════╝ ╔═══╦═══════════════════╗ ║ 1 ║ 30 40 35 30 ║ ║ 2 ║ 30 40 35 30 ║ ╚═══╩═══════════════════╝ ``` -------------------------------- ### Double Box Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Renders tables with double lines forming a box around the entire table and internal double lines for separation. Provides a distinct visual structure. ```none ╔═════╦═════╦═════╦═════╦═════╗ ║ # ║ G ║ H ║ R ║ S ║ ╠═════╬═════╬═════╬═════╬═════╣ ║ 1 ║ 30 ║ 40 ║ 35 ║ 30 ║ ╠═════╬═════╬═════╬═════╬═════╣ ║ 2 ║ 30 ║ 40 ║ 35 ║ 30 ║ ╠═════╬═════╬═════╬═════╬═════╣ ║ SUM ║ 130 ║ 140 ║ 135 ║ 130 ║ ╚═════╩═════╩═════╩═════╩═════╝ ╔═══╦════╦════╦════╦════╗ ║ 1 ║ 30 ║ 40 ║ 35 ║ 30 ║ ╠═══╬════╬════╬════╬════╣ ║ 2 ║ 30 ║ 40 ║ 35 ║ 30 ║ ╚═══╩════╩════╩════╩════╝ ``` -------------------------------- ### ColumnWidthTooSmallError Exception Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/api.rst Exception for column widths that are too small. ```APIDOC ## ColumnWidthTooSmallError ### Description Raised when a specified column width is too small to accommodate its content. ``` -------------------------------- ### Zero Cell Padding for Tight Layout Source: https://context7.com/denvercoder1/table2ascii/llms.txt Set `cell_padding=0` to remove all space between cell content and borders, creating a compact table layout. ```python from table2ascii import table2ascii, PresetStyle, Alignment # Zero padding — tight layout output = table2ascii( header=["Name", "Score"], body=[["Alice", "99"], ["Bob", "82"]], style=PresetStyle.ascii_box, cell_padding=0, ) print(output) ``` -------------------------------- ### TableStyleTooShortWarning Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/api.rst Warning for table styles that are too short. ```APIDOC ## TableStyleTooShortWarning ### Description Issued when a custom table style definition is shorter than expected, potentially leading to incomplete borders. ``` -------------------------------- ### Thin Double Rounded Table Style Source: https://github.com/denvercoder1/table2ascii/blob/main/docs/source/styles.rst Renders a table with thin double-line rounded borders. Combines distinctness with a softer edge. ```none ╭─────┬───────────────────────╮ │ # │ G H R S │ ╞═════╪═══════════════════════╡ │ 1 │ 30 40 35 30 │ ├─────┼───────────────────────┤ │ 2 │ 30 40 35 30 │ ╞═════╪═══════════════════════╡ │ SUM │ 130 140 135 130 │ ╰─────┴───────────────────────╯ ╭───┬───────────────────╮ │ 1 │ 30 40 35 30 │ ├───┼───────────────────┤ │ 2 │ 30 40 35 30 │ ╰───┴───────────────────╯ ```