How to Disable Label Rendering in Outfancy Tables: 2 Proven Methods
You can disable label rendering in outfancy tables either globally by calling set_show_labels(False) on the Table instance, or per-render by passing label_list=False to the render() method.
Outfancy provides a lightweight Python library for rendering formatted tables in terminal environments. When you need to display raw data without column headers, disabling label rendering gives you cleaner output for automated processing or minimalist displays.
Understanding the Label Rendering Pipeline
Outfancy’s table rendering pipeline constructs output through three distinct phases implemented in outfancy/table.py:
- Data preparation – Columns are reordered, widths are calculated, and the table body (
pre_table) is generated. - Label handling – The
check_label_listfunction creates or validates the list of column headers. - Final composition – The
post_rendermethod concatenates the optional label line with the table body.
The visibility of the label line depends on two control points: the self.show_labels instance attribute (default True at line 177) and the label_list parameter passed to render(). The final guard at line 273 in post_render only includes the header when label_list is not False and self.show_labels is True.
Global Disabling Using set_show_labels()
For consistent header suppression across multiple render calls, toggle the show_labels attribute using the public API setter.
The Table.set_show_labels() method (defined at line 187 in outfancy/table.py) modifies the instance flag that governs whether post_render includes the label line:
from outfancy import Table
tbl = Table()
tbl.set_show_labels(False) # Disable headers for this instance
print(tbl.render(dataset)) # No header line appears
This approach affects every subsequent call to render() until you explicitly re-enable labels.
Per-Render Disabling Using the label_list Parameter
When you need occasional header suppression without changing the Table’s global state, pass label_list=False directly to the render() method:
from outfancy import Table
tbl = Table()
# Suppress header only for this specific render call
print(tbl.render(dataset, label_list=False))
This parameter overrides the self.show_labels flag for a single execution, making it ideal for conditional formatting logic.
Practical Code Examples
The following examples demonstrate both approaches using the included example dataset.
Example 1: Global Disable
from outfancy import Table, example_dataset
t = Table()
t.set_show_labels(False) # Turn off headers permanently for this instance
print(t.render(example_dataset.dataset))
Example 2: Disable for a Single Render
from outfancy import Table, example_dataset
t = Table()
# Instance retains default show_labels=True, but this call skips the header
print(t.render(example_dataset.dataset, label_list=False))
Example 3: Re-enabling Labels After Disabling
from outfancy import Table, example_dataset
t = Table()
t.set_show_labels(False)
print("Without labels:")
print(t.render(example_dataset.dataset))
t.set_show_labels(True) # Re-enable headers
print("\nWith labels:")
print(t.render(example_dataset.dataset))
Summary
- Global control: Use
Table.set_show_labels(False)to disable labels for all future renders on that instance. - Per-call control: Pass
label_list=Falsetorender()to suppress headers for a single output. - Default behavior: The
show_labelsattribute defaults toTrueinoutfancy/table.pyline 177. - Implementation: The
post_rendermethod at line 273 contains the logic gate that checks both flags before including the header line.
Frequently Asked Questions
What is the default behavior for labels in outfancy tables?
By default, outfancy displays column labels. The show_labels attribute initializes to True in the Table class constructor located at outfancy/table.py line 177, causing post_render to include the header line unless explicitly disabled.
Can I toggle label visibility multiple times on the same Table instance?
Yes. The set_show_labels() method is a runtime setter that you can call repeatedly. Each call updates the instance attribute immediately, affecting only the subsequent render() invocations without requiring you to recreate the Table object.
Where is the label rendering logic implemented in the source code?
The core logic resides in outfancy/table.py. The check_label_list function handles header validation, while the final rendering decision occurs in post_render at line 273, which checks both self.show_labels and the label_list parameter before concatenating the header.
Does disabling labels affect table width calculations?
No. Width calculations occur during the data preparation phase before label handling. Whether you disable labels globally or per-render, column widths are determined by the dataset content, ensuring consistent alignment between labeled and unlabeled outputs.
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:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →