How to Customize Labels in Outfancy Tables: 3 Methods Explained

You can customize labels in outfancy tables by passing a custom label_list to Table.render(), setting label_list=False to hide headers, or modifying the internal check_label_list mapping for auto-generated defaults.

Outfancy is a Python library for rendering formatted tables in the terminal. When generating output, you have full control over the header labels displayed above each column. This guide explains how to customize labels in outfancy tables using parameters and internal rendering methods found in carlosplanchon/outfancy.

Three Ways to Customize Table Labels

The Table.render() method in outfancy/table.py accepts a label_list argument that determines what appears in the header row. If you omit this parameter, the library automatically generates labels based on detected column types via the internal check_label_list helper.

Pass an Explicit Label List

The most direct way to customize labels is to provide a list of strings to Table.render(). According to the source code in outfancy/table.py (lines 80-88), Table.render() forwards your label_list to check_label_list(), which validates the entries and builds the final ordered_label_list used in the header. The list must match the number of columns in your data; the library will pad or truncate it if necessary.

import outfancy.table as ot

tbl = ot.Table()
data = [
    (1, "Alice", 28),
    (2, "Bob", 34),
]

# Custom headers for the three columns

custom_labels = ["User-ID", "Full Name", "Age (y)"]
print(tbl.render(data, label_list=custom_labels))

This renders "User-ID", "Full Name", and "Age (y)" as the column headers instead of the auto-generated defaults.

Hide the Header Row Completely

To suppress the label row entirely, pass label_list=False to render() or call set_show_labels(False) before rendering. This functionality is handled in outfancy/table.py (lines 50-56), where the header-visibility flag determines whether to skip label processing entirely.

tbl = ot.Table()
tbl.set_show_labels(False)  # Alternative: pass label_list=False to render()

print(tbl.render(data, label_list=False))

The table renders without any header line, showing only the data rows.

Modify the Auto-Generated Label Mapping

When you omit label_list, check_label_list (lines 48-61) builds default labels like "Id", "Name", "Date", and "Description" based on the column's detected data type. You can influence this by providing a custom data_type_list or by overriding the internal mapping.

For advanced customization, you can monkey-patch the check_label_list method to alter the default label scheme without modifying the library source:

from outfancy import table

def my_check_label_list(self, *args, **kwargs):
    # Call original implementation

    labels = table.Table.check_label_list(self, *args, **kwargs)
    # Replace generic labels

    return [lbl.replace("Description", "Notes") for lbl in labels]

# Apply the patch once at import time

table.Table.check_label_list = my_check_label_list

tbl = table.Table()
print(tbl.render(data))  # Shows "Id", "Name", "Notes" instead of "Description"

How Label Processing Works Internally

Understanding the internal flow helps debug custom label issues. The rendering pipeline in outfancy/table.py processes labels through three stages:

  1. Input Validation: Table.render() receives the label_list argument and calls self.check_label_list(label_list, data_type_list, width, order, separator).
  2. List Processing: check_label_list validates the supplied list, pads or truncates it to match the column count, and rebuilds any missing entries using the hard-coded data type mapping.
  3. Header Assembly: The method returns an ordered_label_list that is merged with column separators and rendered by the post-render routine.

This flow ensures that your custom labels appear exactly as specified, while providing sensible defaults when you rely on auto-generation.

Summary

  • Explicit control: Pass a string list to label_list in Table.render() to define exact column headers.
  • Header suppression: Set label_list=False or use set_show_labels(False) to hide the header row.
  • Default customization: Override check_label_list in outfancy/table.py to change auto-generated labels based on data types.
  • Validation: The library automatically pads or truncates your label list to match the column count, ensuring consistent rendering.

Frequently Asked Questions

Can I disable the header row in outfancy tables?

Yes. Set label_list=False when calling Table.render(), or call tbl.set_show_labels(False) before rendering. As implemented in outfancy/table.py (lines 50-56), this flag suppresses the entire header row generation.

What happens if my label list has fewer items than columns?

The check_label_list method automatically pads your list with auto-generated labels based on detected column types. Conversely, if you provide too many labels, the list is truncated to match the column count. This validation occurs in outfancy/table.py (lines 48-61).

Where is the label auto-generation logic located?

The auto-generation mapping lives inside the check_label_list method in outfancy/table.py (lines 48-61). This method translates detected data types (id, name, date, description) into default header strings like "Id", "Name", "Date", and "Description".

Can I customize labels for specific data types only?

Yes. While you can pass a complete custom list to label_list, you can also modify the default behavior by overriding the check_label_list method or providing a custom data_type_list parameter to influence how the library generates missing labels. The mapping between data types and default labels is hard-coded in check_label_list but can be altered via monkey-patching for application-wide changes.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →